M
Mattias
Hi all
Having Access 2002 and have a database where I handle 4 different pictures
for every record.
In the main table I only store the picturename and have a separate table for
storing the path "tblPath"
In tblPath I have registred 4 differents paths.
The problem here is that I can only display from one folder (path) at the
time.
What can be wrong here?
Thank you for your help in advance!
Mattias
The code below is the formbased code where I display the pictures.
Private Sub Form_Current()
CallDisplayImage
CallDisplayImage2
CallDisplayImage3
CallDisplayImage4
Refresh
End Sub
Private Sub Form_AfterUpdate()
CallDisplayImage
CallDisplayImage2
CallDisplayImage3
CallDisplayImage4
Refresh
End Sub
Private Sub txtImageName_AfterUpdate()
CallDisplayImage
Refresh
End Sub
Private Sub txtImageName2_AfterUpdate()
CallDisplayImage2
Refresh
End Sub
Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName)
End Sub
Private Sub CallDisplayImage2()
Me!txtImageNote2 = DisplayImage(Me!ImageFrame2, Me!txtImageName2)
End Sub
The code below is placed in a module.
Public Function DisplayImage(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
'Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "Finns ej bild."
Else
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath1]", "tblPath") & "\" &
strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = ""
End If
End With
Exit_DisplayImage:
DisplayImage = strResult
Exit Function
Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Finns ej bild."
Resume Exit_DisplayImage:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "Ett fel uppstod när bilden skulle visas."
Resume Exit_DisplayImage:
End Select
End Function
Public Function DisplayImage2(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage2
Dim strResult As String
'Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "Finns ej bild."
Else
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath2]", "tblPath") & "\" &
strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = ""
End If
End With
Exit_DisplayImage2:
DisplayImage2 = strResult
Exit Function
Err_DisplayImage2:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Finns ej bild."
Resume Exit_DisplayImage2:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "Ett fel uppstod när bilden skulle visas."
Resume Exit_DisplayImage2:
End Select
End Function
----------------------------------------------------------------------------
----
I only looked at your code enough to see a DLookup that was retrieving a
path, that had no selection... no criteria... without some criteria to
determine which path to choose, you'll get the first one it retrieves. How
is it supposed to know which path to return, if you don't give it some
information?
Please clarify, if need be, here in the newsgroup, not by e-mail. Thanks.
Larry Linson
Microsoft Access MVP
----------------------------------------------------------------------------
----
Hi
Thank you for your reply. I do understand your point of view..but I do not
really understand why as I am calling 4 separete pulic functions, one for
each path I need to display pictures from. The paths are registred in
tblPath where I have named 4 txt fields PicturePath1 - PicturePath4.
Function no 1: "DisplayImage"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath1]", "tblPath") & "\" &
strImagePath
End If
Function no 2: "DisplayImage2"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath2]", "tblPath") & "\" &
strImagePath
End If
Function no 3: "DisplayImage3"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath3]", "tblPath") & "\" &
strImagePath
End If
Function no 4: "DisplayImage4"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath4]", "tblPath") & "\" &
strImagePath
End If
So in the form where I would like to display the pictures,
If I want to display Picture1 I call DisplayImage
If I want to display Picture2 I call DisplayImage2
If I want to display Picture3 I call DisplayImage3
If I want to display Picture4 I call DisplayImage4
In my mind If I do like above it should not have to choose in every
function, because I tell the exact field use tblPath!
If this is wrong, can you help me in the right direction what to use as
criteria in the function.
Thanks
Mattias
----------------------------------------------------------------------------
-----
Mattias
If you have *only* 1 record (with 4 fields [PicturePath1]..[PicturePath4])
then your DLookup should work. The point that Larry was making was if there
is more than 1 record you would need to specify in the 3rd parameter of
DLookup a where condition so that the correct record would be selected.
HTH
Andy
Having Access 2002 and have a database where I handle 4 different pictures
for every record.
In the main table I only store the picturename and have a separate table for
storing the path "tblPath"
In tblPath I have registred 4 differents paths.
The problem here is that I can only display from one folder (path) at the
time.
What can be wrong here?
Thank you for your help in advance!
Mattias
The code below is the formbased code where I display the pictures.
Private Sub Form_Current()
CallDisplayImage
CallDisplayImage2
CallDisplayImage3
CallDisplayImage4
Refresh
End Sub
Private Sub Form_AfterUpdate()
CallDisplayImage
CallDisplayImage2
CallDisplayImage3
CallDisplayImage4
Refresh
End Sub
Private Sub txtImageName_AfterUpdate()
CallDisplayImage
Refresh
End Sub
Private Sub txtImageName2_AfterUpdate()
CallDisplayImage2
Refresh
End Sub
Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName)
End Sub
Private Sub CallDisplayImage2()
Me!txtImageNote2 = DisplayImage(Me!ImageFrame2, Me!txtImageName2)
End Sub
The code below is placed in a module.
Public Function DisplayImage(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
'Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "Finns ej bild."
Else
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath1]", "tblPath") & "\" &
strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = ""
End If
End With
Exit_DisplayImage:
DisplayImage = strResult
Exit Function
Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Finns ej bild."
Resume Exit_DisplayImage:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "Ett fel uppstod när bilden skulle visas."
Resume Exit_DisplayImage:
End Select
End Function
Public Function DisplayImage2(ctlImageControl As Control, strImagePath As
Variant) As String
On Error GoTo Err_DisplayImage2
Dim strResult As String
'Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "Finns ej bild."
Else
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath2]", "tblPath") & "\" &
strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = ""
End If
End With
Exit_DisplayImage2:
DisplayImage2 = strResult
Exit Function
Err_DisplayImage2:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Finns ej bild."
Resume Exit_DisplayImage2:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "Ett fel uppstod när bilden skulle visas."
Resume Exit_DisplayImage2:
End Select
End Function
----------------------------------------------------------------------------
----
I only looked at your code enough to see a DLookup that was retrieving a
path, that had no selection... no criteria... without some criteria to
determine which path to choose, you'll get the first one it retrieves. How
is it supposed to know which path to return, if you don't give it some
information?
Please clarify, if need be, here in the newsgroup, not by e-mail. Thanks.
Larry Linson
Microsoft Access MVP
----------------------------------------------------------------------------
----
Hi
Thank you for your reply. I do understand your point of view..but I do not
really understand why as I am calling 4 separete pulic functions, one for
each path I need to display pictures from. The paths are registred in
tblPath where I have named 4 txt fields PicturePath1 - PicturePath4.
Function no 1: "DisplayImage"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath1]", "tblPath") & "\" &
strImagePath
End If
Function no 2: "DisplayImage2"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath2]", "tblPath") & "\" &
strImagePath
End If
Function no 3: "DisplayImage3"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath3]", "tblPath") & "\" &
strImagePath
End If
Function no 4: "DisplayImage4"
If InStr(1, strImagePath, "\") = 0 Then
strImagePath = DLookup("[PicturePath4]", "tblPath") & "\" &
strImagePath
End If
So in the form where I would like to display the pictures,
If I want to display Picture1 I call DisplayImage
If I want to display Picture2 I call DisplayImage2
If I want to display Picture3 I call DisplayImage3
If I want to display Picture4 I call DisplayImage4
In my mind If I do like above it should not have to choose in every
function, because I tell the exact field use tblPath!
If this is wrong, can you help me in the right direction what to use as
criteria in the function.
Thanks
Mattias
----------------------------------------------------------------------------
-----
Mattias
If you have *only* 1 record (with 4 fields [PicturePath1]..[PicturePath4])
then your DLookup should work. The point that Larry was making was if there
is more than 1 record you would need to specify in the 3rd parameter of
DLookup a where condition so that the correct record would be selected.
HTH
Andy