Hi,
I used some code from the MS website to enable display of images on a form based on the path stored in a text field, all worked OK until I tried to be clever and use a subform to display multiple images linked by EventID.
The problem is that, even though the record ID in the subform shows the next picture ID, when next record button is pressed, the picture remains the same.
Anyone any ideas as to what's not happening. MS code below.
I used some code from the MS website to enable display of images on a form based on the path stored in a text field, all worked OK until I tried to be clever and use a subform to display multiple images linked by EventID.
The problem is that, even though the record ID in the subform shows the next picture ID, when next record button is pressed, the picture remains the same.
Anyone any ideas as to what's not happening. MS code below.
Code:
Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage
Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer
With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No image name specified."
Else
If InStr(1, strImagePath, "\") = 1 Then
' Path is relative
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True
.Picture = strImagePath
'.Requery
strResult = "Image found and displayed."
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 = "Can't find image in the specified name."
Resume Exit_DisplayImage:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function