# Thread: Image does not appear in a report when image does not exist

1. Registered User
Join Date
May 2006
Posts
386

## Unanswered: Image does not appear in a report when image does not exist

Hi All,
It may be a simple issue for you but for me it is just not working, I have the following code on the On Format event of my report, it works fine if an image exists in the PhotographPath of my table, however, when a record does not have an image saved, it does not work.

Basically, where a record does not have an image, i want the system to get a picture file JPG which says "No Image" and this file exists in the folde where pictures are saved, but it does not work. Below is my code: any help would be much appreciated:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If IsNull(Me!PhotographPath) Then
Me![ImageFrame].Picture = ""
Else
Me![ImageFrame].Picture = Me![PhotographPath]

End If

End Sub

2. Moderator
Join Date
Mar 2009
Posts
5,442
Why don't you use:
Code:
If IsNull(Me!PhotographPath) Then
Me![ImageFrame].Picture = "<MyapplicationPath\NoPicture.jpg>"

3. Registered User
Join Date
May 2006
Posts
386
Hi Sinndho, Thank you for your resopnse.
I tried your code, but I get Error 2220 . The message says my DB can't open the file 'Y:\'.

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
so what do you think that error message is telling you?

my guess is that the file nopicture.jpg isn't in that location.

Code:
If IsNull(Me!PhotographPath) Then
Me![ImageFrame].Picture = "<path\to\image\imagenotfound.picture>"
Else
Me![ImageFrame].Picture = Me![PhotographPath]

End If

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
if that doesn't work, anmd I dont' see why it shouldnt' you can play cute little games and have a picture/image control already loaded with that image and hide/show as required

6. Registered User
Join Date
May 2006
Posts
386
This is the whole code I use and a picture is not saved in the path folder, it should show the picuture that says NoPicture.JPG. However, everytime I run it, the code breaks on the line that I have highlighted in Red.

Option Compare Database
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If IsNull(Me!PhotographPath) Then
Me![ImageFrame].Picture = "<PhotographPath\NoPicture.jpg>"

Else

Me![ImageFrame].Picture = Me![PhotographPath]

End If

End Sub

7. Moderator
Join Date
Mar 2009
Posts
5,442
1. You need to replace:
Code:
"<PhotographPath\NoPicture.jpg>"
by the actual path to an existing picture file.

2. What's Me![[PhotographPath], a textbox? If yes is it bound to a field in the database? If yes, what contains that field?

8. Registered User
Join Date
May 2006
Posts
386
Hi Sindho, Thank you for this. I tried this and did exactly what you suggested. However, I still get the same error. And yes, PhotographPath is name of the text box as well as the image path where photopath is saved in the table.

This is how i changed the code:
Me![ImageFrame].Picture = "\\ntserver\employees\logo.jpg"
Basically, it is working very fine on my form but it does not work on the report.

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
check the control type you may need to set another property in place of .picture
ferinstance if its an image contorl then set the image

10. Registered User
Join Date
May 2006
Posts
386
Sorry, I did not quite understand this, do you mean I should change the word Picture to something else? I am sorry but I am not quite good with codes?

11. Moderator
Join Date
Mar 2009
Posts
5,442
I tested using a simple Image control (not a Bound or Unbound Object Frame) and it works like this:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If IsNull(Me.PhotographPath.Value) Then
Me.Image1.Picture = "C:\Documents and Settings\Sinndho\My documents\My pictures\548987ce-d2b3-4c18-ae59-ebde.png"
Else
Me.Image1.Picture = Me.PhotographPath.Value
End If

End Sub

12. Registered User
Join Date
May 2006
Posts
386
I am still getting the same error. Maybe I have to explain this clearly so you can help me from start. I have one table called "tblemployees" one of its fields is called PhotographPath. This is where we have the path to photos. In this path, some employees photo names are stored and there photos are saved in the relevant folder, and some employees photo names are stored BUT there photos are not saved in the folder (There are many of them) and there are some employees with no information in the Photographpath because we still do not have their photos.

I would be most grateful if you could suggest a code where if the photographpath is null or where the photographpath is not null but there is no photo saved in the folder then it should display the photo that says "NoPicture.jpg". But if the photo exists in the folder and the photographpath has the name saved, then it should display the photo.

i really hope you can help. Thank you very much for all your support.

13. Moderator
Join Date
Mar 2009
Posts
5,442
Maybe like this:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If IsNull(Me.PhotographPath.Value) Or Len(Dir(Nz(Me.PhotographPath.Value, ""))) = 0 Then

' No picture path into table or file does not exists:
'  --> Display "No Picture" picture (the corresponding file must exist).
'
Me.Image1.Picture = "C:\Documents and Settings\Sinndho\My documents\My pictures\548987ce-d2b3-4c18-ae59-ebde.png"
Else

' Display the (existing) picture related to the path stored into the table.
'
Me.Image1.Picture = Me.PhotographPath.Value
End If

End Sub

14. Registered User
Join Date
May 2006
Posts
386
Hi Sindho, first of all, thank you for your response.
I pasted your code and replaced the photo folder path as necessary but it is not giving me this error " Run-Time error 22202 and the code breaks on the bold line below:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If IsNull(Me.PhotographPath.Value) Or Len(Dir(Nz(Me.PhotographPath.Value, ""))) = 0 Then

' No picture path into table or file does not exists:
' --> Display "No Picture" picture (the corresponding file must exist).
'
Me.ImageFrame.Picture = "\\ntserver\Company Shared Folder\Photos\NoPicture.JPG"
Else

' Display the (existing) picture related to the path stored into the table.
'
Me.ImageFrame.Picture = Me.PhotographPath.Value
End If

End Sub
I hope you can help.

15. Moderator
Join Date
Mar 2009
Posts
5,442