Full Version: Displaying Images on Access Report - Error on empty imagepath
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
heecack
I followed these instructions and it works perfectly: http://support.microsoft.com/kb/148463

However, there are some records that do not have images so the imagepath is empty. This causes an error right off: "Microsoft Office can't opent the file: XXX"

What code can I add to make it just skip if the imagepath is empty?

Any help is truly appreciated.

Thanks,
Sheila
fkegley
I would change the code in both places to this:

Private Sub Form_Current()
On Error Resume Next
If IsNull(Me![ImagePath] Then
Else
Me![ImageFrame].Picture = Me![ImagePath]
End If


End Sub
heecack
fkegley, Thanks so much for your reply!

I used your suggested code and the report ran but for the images that were missing it filled them in with the images from the record above. I need it to leave that space empty or show the default image to signify there was no entry for that record.

Any other suggestions?

Thanks,
Sheila
Bob_L
1. create an image of a white square so it blends in (if that is your background color) and then name it blank.jpg or something like that.

2. Use Frank's code:
CODE
Private Sub Form_Current()
   On Error Resume Next
      If IsNull(Me![ImagePath] Then
         Me![ImageFrame].Picture = "C:\YourPathToTheBlank"
      Else
         Me![ImageFrame].Picture = Me![ImagePath]
      End If
End Sub


That is one way around it.

Also - Frank if you aren't going to have something after

If IsNull(Me![ImagePath] Then

Just change it to

If Not IsNull(Me![ImagePath] Then

So you don't have an Else where you don't need an Else.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.