Last time I struck this, I placed an unbound toggle button on the form, so
the user could show the photos if they wish, or hide them for a fast browse.
Without cutting it down, this was the code.
Private Sub tglShowPhoto_AfterUpdate()
On Error GoTo Err_Handler
With Me.tglShowPhoto
If .Value Then
Call LoadTheImage(Me.ClientPhoto)
.ControlTipText = "Hide photos"
Else
Me.imgClientPhoto.Visible = False
Me.txtNoImage.Visible = False
.ControlTipText = "Show photos"
End If
End With
Exit_Handler:
Exit Sub
Err_Handler:
Call LogError(Err.Number, Err.Description, conMod &
".tglShowPhoto_AfterUpdate")
Resume Exit_Handler
End Sub
Private Sub Form_Current()
Call LoadTheImage(Me.ClientPhoto)
End Sub
Private Function LoadTheImage(varFile As Variant) As Boolean
On Error GoTo Err_Handler
'Purpose: Show/hide the picture, loading from file.
'Return: True if image loaded.
Dim bShow As Boolean
Dim strFullPath As String
With Me.imgClientPhoto
If (Me.tglShowPhoto.Value) Then
If Not (IsNull(varFile) Or IsNull(Me.txtImageFolder)) Then
'Check the file is still here. Can't show if it is not.
strFullPath = Me.txtImageFolder & varFile
If FileExists(strFullPath) Then
bShow = True
If .Picture = strFullPath Then
'do nothing
Else
Me.NavigationButtons = False 'This prevents a GPF
if the user move to another record before image is loaded.
.Picture = strFullPath
Me.NavigationButtons = True
End If
End If
End If
If .Visible <> bShow Then
.Visible = bShow
End If
Me.txtNoImage.Visible = Not bShow
Else
bShow = False
If .Visible Then
.Visible = False
End If
Me.txtNoImage.Visible = False
End If
End With
Exit_Handler:
Exit Function
Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".LoadTheImage")
Resume Exit_Handler
End Function
If you want the error handler, see:
http://members.iinet.net.au/~allenbrowne/ser-23a.html