If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Linked image and error display simultaneously
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 |
#2
|
|||
|
|||
Linked image and error display simultaneously
wrote in message
... 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 see where you're making lblMsg visible, but not where you're making it invisible. If you move to a record with no picture, the label will be made visible; if you then move to a record with a picture, the label will still be visible. Try adding the line Me.lblMsg.Visible = False within your final Else...End If block (where you resize the picture and make it visible). Carl Rapson |
#3
|
|||
|
|||
Linked image and error display simultaneously
On Apr 21, 8:23*am, "Carl Rapson"
wrote: wrote in message ... 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 see where you're making lblMsg visible, but not where you're making it invisible. If you move to a record with no picture, the label will be made visible; if you then move to a record with a picture, the label will still be visible. Try adding the line Me.lblMsg.Visible = False within your final Else...End If block (where you resize the picture and make it visible). Carl Rapson- Hide quoted text - - Show quoted text - Thank you so much--worked like a charm! DJohnson |
Thread Tools | |
Display Modes | |
|
|