Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't find image path when form opens

Status
Not open for further replies.

ekwstats

MIS
Feb 2, 2004
70
US
First off...sorry to keep asking questions and second thank you so much for the help. I am a programmer by example and this site has been great.
My program is almost done, but I have nagging issues. The database stores the image path and it loads the images on the form just fine except when you open/close the form it gives a "can't open the file imagename.jpg". This is the path that I HAD to put in when I added the image object. It changes on the fly after the form opens and oncurrent, but when the form first opens and closes the error keeps popping up despite all attempts to change the path at onLoad, onError, onOpen. I put in a message box that tells me the path is getting changed, but the darn message just won't go away and I can't seem to error it out either. I took out all of the code and the message is still there so it's the Image.Picture = Path where the Path is no longer valid that is causing the problem.
How was I supposed to add an image to this form if the install path is not static and therefore the Path will be a changing variable? It's probably something really easy.
Thanks!!
 
How are ya ekwstats . . . . .

You should be changing the [blue]Picture Property[/blue] (path & filename), in the [purple]On Current Event[/purple] of the form. If this is not so, its possible to leave indeterminants in code.

Just how is your code changing the [blue]Picture Property[/blue]?

If ya can post that code, any tipster can readily tell ya what to do . . . . .

Calvin.gif
See Ya! . . . . . .
 
imgShow.picture = C:\Program Files\Program Name\Picutures\default.jpg
Type = Linked (tried embedded w/same results)
Size Mode = Zoom

Here is the code and I have test Messages boxes that pop up to try and figure out why the picture path is still throwing an eror.
The MsgBox Me.imgShow.Picture always shows a valid path for each of the different events. Am at a loss on this. I actually have this problem on all of my forms and reports where a picture is linked.

Private Sub Form_Load()
Me.imgShow.Picture = Application.CurrentProject.Path & "\pictures\default.jpg"

MsgBox Me.imgShow.Picture

Dim db As DAO.Database
Dim obj As AccessObject
Dim dbs As Object

Set db = CurrentDb
Set dbs = Application.CurrentProject

' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
If obj.name <> "frmAnimals" Then
If obj.IsLoaded = True Then
DoCmd.Close acForm, obj.name
End If
End If
Next obj

End Sub

'Picture Settings
Private Sub Form_Current()
Me.imgShow.Picture = Application.CurrentProject.Path & "\pictures\default.jpg"
MsgBox Me.imgShow.Picture

Dim strPhotoPath
Dim objScript

strPhotoPath = Me.txtPhotoPath

Set objScript = CreateObject("Scripting.FileSystemObject")

If [Photo] <> "" Then
If objScript.FileExists(strPhotoPath) Then
Me.imgShow.Picture = strPhotoPath
Else
Me.txtPhotoPath = ""
MsgBox "The selected photo can not be found and has been reset to the default."
Me.imgShow.Picture = Application.CurrentProject.Path & "\pictures\default.jpg"

End If
Else
Me.imgShow.Picture = Application.CurrentProject.Path & "\pictures\default.jpg"
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
Me.imgShow.Picture = Application.CurrentProject.Path & "\pictures\default.jpg"
MsgBox Me.imgShow.Picture

Dim db As DAO.Database
Dim td As DAO.TableDef

Set db = CurrentDb
Set td = db.TableDefs("tblHorse")


newlenstr = (Len(td.Connect) - 10)
rpiece = Right(td.Connect, newlenstr)

Me.Caption = "Current Herd: " & rpiece

If rpiece = Application.CurrentProject.Path & "\Herds\sample.eqs" Then
MsgBox "The Sample Herd Is Loaded. This is either a trial version or the previously selected herd no longer exists or has been moved." & _
vbCrLf & vbCrLf & "To Register visit & _
vbCrLf & vbCrLf & "The Trial version will only allow a limited number of animals and procedures to be entered."
End If

End Sub
 
I have been able to fix this by removing all of the code from the form, saving it, then inserting an Image Object and deleting the Picture path so it shows up as (none) now. Before I was not able to set the picture path to none for some reason despite many, many attempts. I then reloading the code. Now it works great. It could just be me, but Access has many, many little quirks like this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top