Pictures - avoid error message if none

S

SusanJane sjl

I was able to do the code to get my pictures to show up on a form, but I get
an error message if there is no picture availabe. How can I avoid this?
Here's the code:
Option Explicit
Dim filename As String, pathname As String
Dim db As DAO.Database


Private Sub Form_Activate()
'find the path of the current database
'which is where the jpegs are stored
Set db = CurrentDb
filename = db.Name
pathname = Mid(filename, 1, Len(filename) - Len(Dir(filename)))

End Sub

Private Sub Form_Current()

'set the picture path
Me.Image6.Picture = pathname & Me.ImagePath

Exit_cmdClose_Click:

End Sub
Private Sub close_Click()
On Error GoTo Err_close_Click


DoCmd.close

Exit_close_Click:
Exit Sub

Err_close_Click:
MsgBox Err.Description
Resume Exit_close_Click

End Sub--
Always grateful for help!!
 
D

Daniel

Check for the picture before using it

using the DIR() you can validate the file exists.

if len(Dir(pathname & Me.ImagePath))>0 then the files exists so you can
assign it to your image control, otherwise do not assign it.
 
S

SusanJane sjl

--
Always grateful for help!!


Daniel said:
Check for the picture before using it

using the DIR() you can validate the file exists.

if len(Dir(pathname & Me.ImagePath))>0 then the files exists so you can
assign it to your image control, otherwise do not assign it.

Daniel,

Thanks for your quick reply. I am a real novice at code. This is what I
did & am still getting error message

Private Sub Form_Current()

'set the picture path
If Len(Dir(pathname & Me.ImagePath)) > 0 Then
Me.Image6.Picture = pathname & Me.ImagePath
End If
Exit_cmdClose_Click:

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top