Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    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
    Emi-UK
    Love begets Love, Help Begets Help

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

  3. #3
    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:\'.
    Emi-UK
    Love begets Love, Help Begets Help

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    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
    Please help as it is really not working for some reason.
    Emi-UK
    Love begets Love, Help Begets Help

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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?
    Have a nice day!

  8. #8
    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.
    Emi-UK
    Love begets Love, Help Begets Help

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    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?
    Emi-UK
    Love begets Love, Help Begets Help

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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
    Have a nice day!

  12. #12
    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.
    Emi-UK
    Love begets Love, Help Begets Help

  13. #13
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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
    Have a nice day!

  14. #14
    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.
    Emi-UK
    Love begets Love, Help Begets Help

  15. #15
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Can you please try with a local path for the file "NoPicture.JPG"? I'm not sure whether an image can be loaded from an UNC path or not. I'll try tomorrow from my office, just to be sure.

    Apart from that, I don't see any reason why this code should not work. Are you sure of the error number (it seems odd to me) and what's the associated message?
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •