Linked Image Path Change Doesn't Work?

dsfcom

Registered User.
Local time
Today, 05:11
Joined
Mar 13, 2007
Messages
72
Hello. I've searched and read a few threads concerning image controls on forms and haven't been able to find a solution to my problem (yet). Anyway, I have a form with two image controls (imgOK1 & imgOK2). The previous and current setting of the "Picture" property for both images is set to "C:\MOM\Graphics\filename.bmp". The location of my images has changed and will change for each user which is "C:\Documents and Settings\user.name\MOM\Graphics\filename.bmp". I'm using the following code to set the .Picture property on form load:

Code:
Dim ImgPath
ImgPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\MOM\Graphics\"
Me.imgOK1.Picture = ImgPath & "imgButton-OK1_25%.bmp"
Me.imgOK2.Picture = ImgPath & "imgButton-OK2_25%.bmp"

When the form is opened, an error stating that the image located at "C:\MOM\Graphics\filename.bmp" cannot be found; once for each image control. Then the form loads and .Picture properties appear to be set correctly as they are displayed fine. I've tried to clear the .Picture properties for both image controls using the properties editor but the original path returns as soon as the property loses focus. Is there a way to programatically set this property and make it stick so the errors are not displayed?
 
Simple Software Solutions

Workaround:

1.
In you main declarations of the form define a boolean flag and set it to False

Dim bFlag As Boolean

2.
On you On Load event place an On Error trap

On Error GoTo ETrap

3.
ETrap:
If Err.Num = ???? (The error number you are receiving) Then
If bFlag = False Then
Resume Next
bFlag = True
Else
Msgbox Err.Description,,Err.Num
End If

Summary:
When the form first opens you currently get the error, the above will trap the error and ignore it, but sets a flag to True to signify that this was trapped on the form load, otherwise if this error occurs again then display the error.

Code simplified for brevity.

CodeMaster::cool:
 
Seems Easy Enough; But No Error Number?

DCrake, The solution provided seems like a great way to alleviate my error problems. However, there is no error number displayed. Only an information message stating:

"[DB NAME] can't open the file '[FILE PATH/NAME]'."

Is there a way to find out what the error number might be if any? What I'd really like to do is fix the problem, but if bypassing the error is the only way to avoid it then I'll do that until another solution presents itself. Thanks in advance for your continued help.

UPDATE: I've tried just trapping general errors using the OnLoad event of the form but the error seems to occur before the OnLoad event fires as the error messages are displayed prior to the form loading then it tries to trap an error that doesn't exist so the code breaks at the MsgBox line that is supposed to display the error message/number. Any ideas?
 
Last edited:
Simple Software Solutions

Ok
Try deleting both the controls and saving the form then attach them again without nominating the source document.

By the way you have not stated which image control you are using. It may be that by using another one will stop this issue.

David
 
I'm using the IMAGE control from the TOOLBOX toolbar. It won't let me add the control without selecting an image to display. When adding the control and CANCEL is clicked as to not add an image, the control goes away with the file location dialogue. Should I be using another type of control?
 
Simple Software Solutions

Hi again

Just tried the following on the form load event



Dim iPath As String
Dim iFile As String

iPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\My Pictures\"
iFile = "WhoAreYa.bmp"

If Dir(iPath & iFile) <> "" Then
Me.Image7.Picture = iPath & iFile
End If


The properties for the image control were as follows

Picture (None)
Picture Type Embedded

Once I droped the control onto the form and nominated a picture I went to the properties and deleted the image name from the picture property. Save the form and opened it and it worked fine

David
 
Great. That's a little more work that I was hoping for but it works. It's funny that the existing image controls wouldn't let me remove the image path. Thanks for your help!
 
Simple Software Solutions

Glad to be of help and your problem has been resolved. Don't forget to update my reputation.

David
 

Users who are viewing this thread

Back
Top Bottom