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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pictures in form - not loading depending how file is opened

Status
Not open for further replies.

Newbie456

Technical User
Nov 21, 2005
37
US
Hi - I posted this earlier, but I still haven't figured out the problem. Please be specific. I am relatively new to access. I've designed a database to be used to keep track of fossils in a lab, and I have pictures embedded in the form to display for each record. It works perfectly, as long as I open the file from within access. If I open the database from my hard drive, the picture can't be found.

I use relative paths, so that the entire database can be burned on CD and shared. So, my paths look something like JPG/picturefilename.jpg.

I'd like to fix this bug. Has anyone seen this before?

Here is my code for pictures:

Option Compare Database
Option Explicit

Private Sub Form_AfterUpdate()
CallDisplayImage
End Sub

Private Sub Form_Current()
CallDisplayImage
End Sub

Private Sub Photographlink_AfterUpdate()
CallDisplayImage
End Sub

Private Sub CallDisplayImage()
Me!Status = DisplayImage(Me!ImageFrame, Me!Photographlink)
End Sub




And here is my module for error messages:

Option Compare Database
Option Explicit

Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage

Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer

With ctlImageControl
If IsNull(strImagePath) Then
.Visible = False
strResult = "No image name specified."
Else
If InStr(1, strImagePath, "\") = 0 Then
' Path is relative
strDatabasePath = CurrentProject.FullName
intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
strDatabasePath = Left(strDatabasePath, intSlashLocation)
strImagePath = strDatabasePath & strImagePath
End If
.Visible = True
.Picture = strImagePath
strResult = "Image found and displayed."
End If
End With

Exit_DisplayImage:
DisplayImage = strResult
Exit Function

Err_DisplayImage:
Select Case Err.Number
Case 2220 ' Can't find the picture.
ctlImageControl.Visible = False
strResult = "Can't find image in the specified name."
Resume Exit_DisplayImage:
Case Else ' Some other error.
MsgBox Err.Number & " " & Err.Description
strResult = "An error occurred displaying image."
Resume Exit_DisplayImage:
End Select
End Function


Thanks a bunch!!
 
I do not understand what you mean by this.

It works perfectly, as long as I open the file from within access. If I open the database from my hard drive, the picture can't be found.

Can you explain what you are saying. What do you mean by "open the file from within Access". I thought your code loads an image into an image control. What do you mean by "if I open the database from my hard drive the picture can not be found". Is the database not on a harddrive? Network?
 
I mean that if I have Access open and go to File, Open, and open the file from the browser menu, the pictures in the form load.

If I go to my computer, open the hard drive folder, and open the file from there, the form will not display the pictures, it says "Can't find image in the specified name."
(see code)

Weird, huh? It's driving me nuts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top