S
shelter
I am running Access 2003.
I have linked images to display on a form. The image path is stored in
tblPersons.Photo. The form has a text box "txt.Photo" which displays
the contents of tblPersons.Photo and cmdAdd and cmdDelete buttons to
allow the user to browse to and add a photo or delete a photo. There
is a hidden lblMsg that displays "Click Add-# to create a photo for
this volunteer" when no photo has been entered. (I have used Add-1,
Add-2 and Add-3 in the text to differentiate between them in different
parts of the code. Once it's working, I will delete the numerical
references.)
My problem is: When a user clicks the Add button and adds a photo, the
photo displays correctly. However, once the user moves to a different
record, then returns to the record, the photo AND the text in lblMsg
are displayed simultaneously (Click Add-3...). I cannot figure out why
this is occuring and appreciate any help. I am not an advanced coder,
and stepping through this didn't reveal anything to my uneducated eye.
Thank you,
DJohnson
The code is modified from John Viescas' example:
Private Sub Form_Current()
' Load the current image, if any, when moving to new row
Dim strPath As String
' If on new record,
If Me.NewRecord Then
' Then set the message
Me.lblMsg.Caption = "Click Add-2 to create a photo for this
volunteer."
' Make it visible
Me.lblMsg.Visible = True
' .. and hide the image frame
Me.imgVolunteer.Visible = False
Exit Sub
End If
' Try to load image - set error trap
On Error Resume Next
' If nothing in the photo text,
If Len(Trim(Nz(Me.Photo))) = 0 Then
' Then set the message
Me.lblMsg.Caption = "Click Add-3 to create a photo for this
volunteer."
' Make it visible
Me.lblMsg.Visible = True
' .. and hide the image frame
Me.imgVolunteer.Visible = False
Else
strPath = Me.Photo
' Check for characters that indicate a full path
If (InStr(strPath, ":") = 0) And (InStr(strPath, "\\") = 0)
Then
' Just a file name, so add the current path
strPath = CurrentProject.Path & "\" & strPath
End If
' Attempt to assign the file name
Me.imgVolunteer.Picture = strPath
' If got an error,
If Err <> 0 Then
' Then set the message
Me.lblMsg.Caption = "Photo not found. Click Add to
correct."
' Make it visible
Me.lblMsg.Visible = True
' .. and hide the image frame
Me.imgVolunteer.Visible = False
Else
' Resize the picture
Me.imgVolunteer.Width = 2160
' Reveal the picture
Me.imgVolunteer.Visible = True
' And set the form palette so the picture displays
correctly
Me.PaintPalette = Me.imgVolunteer.ObjectPalette
End If
End If
End Sub
I have linked images to display on a form. The image path is stored in
tblPersons.Photo. The form has a text box "txt.Photo" which displays
the contents of tblPersons.Photo and cmdAdd and cmdDelete buttons to
allow the user to browse to and add a photo or delete a photo. There
is a hidden lblMsg that displays "Click Add-# to create a photo for
this volunteer" when no photo has been entered. (I have used Add-1,
Add-2 and Add-3 in the text to differentiate between them in different
parts of the code. Once it's working, I will delete the numerical
references.)
My problem is: When a user clicks the Add button and adds a photo, the
photo displays correctly. However, once the user moves to a different
record, then returns to the record, the photo AND the text in lblMsg
are displayed simultaneously (Click Add-3...). I cannot figure out why
this is occuring and appreciate any help. I am not an advanced coder,
and stepping through this didn't reveal anything to my uneducated eye.
Thank you,
DJohnson
The code is modified from John Viescas' example:
Private Sub Form_Current()
' Load the current image, if any, when moving to new row
Dim strPath As String
' If on new record,
If Me.NewRecord Then
' Then set the message
Me.lblMsg.Caption = "Click Add-2 to create a photo for this
volunteer."
' Make it visible
Me.lblMsg.Visible = True
' .. and hide the image frame
Me.imgVolunteer.Visible = False
Exit Sub
End If
' Try to load image - set error trap
On Error Resume Next
' If nothing in the photo text,
If Len(Trim(Nz(Me.Photo))) = 0 Then
' Then set the message
Me.lblMsg.Caption = "Click Add-3 to create a photo for this
volunteer."
' Make it visible
Me.lblMsg.Visible = True
' .. and hide the image frame
Me.imgVolunteer.Visible = False
Else
strPath = Me.Photo
' Check for characters that indicate a full path
If (InStr(strPath, ":") = 0) And (InStr(strPath, "\\") = 0)
Then
' Just a file name, so add the current path
strPath = CurrentProject.Path & "\" & strPath
End If
' Attempt to assign the file name
Me.imgVolunteer.Picture = strPath
' If got an error,
If Err <> 0 Then
' Then set the message
Me.lblMsg.Caption = "Photo not found. Click Add to
correct."
' Make it visible
Me.lblMsg.Visible = True
' .. and hide the image frame
Me.imgVolunteer.Visible = False
Else
' Resize the picture
Me.imgVolunteer.Width = 2160
' Reveal the picture
Me.imgVolunteer.Visible = True
' And set the form palette so the picture displays
correctly
Me.PaintPalette = Me.imgVolunteer.ObjectPalette
End If
End If
End Sub