Results 1 to 12 of 12
  1. #1
    dtbconfusion is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    7

    Displaying Photos/No Photos on a Form based on File Path

    Hi! I'm a new Access user and I'm trying to display photos in my access form based on a file path to the image. Sorry if my question is unclear--let me know how I can clarify anything!



    I have 3 possible images that can show up on a form, and 3 columns in my table which can contain a file path. The code I have is able to update the image on the form if there is a file path in the field, but the image field does not update if the field in the table is blank, which means that it still displays the image from the previous form.

    I need to have the image in the form be blank if there is no image path in the table. This is what I have that does display photos--what can I add to make it so that a null field in the table displays nothing??

    Thank you in advance!
    Private Sub Form_Current()

    On Error Resume Next
    Me![ImageFrame].Picture = Me![ImagePath1]

    On Error Resume Next
    Me![ImageFrame2].Picture = Me![ImagePath2]

    On Error Resume Next
    Me![ImageFrame3].Picture = Me![ImagePath3]

    End Sub

    Private Sub ImagePath1_AfterUpdate()
    On Error Resume Next
    Me![ImageFrame].Picture = Me![ImagePath1]

    End Sub

    Private Sub ImagePath2_AfterUpdate()
    On Error Resume Next
    Me![ImageFrame2].Picture = Me![ImagePath2]

    End Sub

    Private Sub ImagePath3_AfterUpdate()
    On Error Resume Next
    Me![ImageFrame3].Picture = Me![ImagePath3]

    End Sub

  2. #2
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Maybe:

    If isnull(Me![ImagePath1]) then
    Me![ImageFrame].Picture = null
    Else
    Me![ImageFrame].Picture = Me![ImagePath1]
    End If

  3. #3
    dtbconfusion is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    7
    Hi Bulzie, thanks for the reply! I'm not sure I'm getting this right--I'm getting "Run-time error '13': Type mismatch". What am I doing incorrectly??


    Private Sub Form_Current()


    If IsNull(Me![ImagePath1]) Then
    Me![ImageFrame].Picture = Null
    Else
    Me![ImageFrame].Picture = Me![ImagePath1]
    End If

  4. #4
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Try Me![ImageFrame].Picture = ""

  5. #5
    dtbconfusion is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    7
    Yes! This totally works! You're a lifesaver.

    I do have one more question though--the images I have are all named after primary keys (plus _1, _2, or _3), and some of my records have a file path in the table that doesn't lead to anywhere, as there are only 2 photos.

    I can delete all of the non-existent paths off of the table, but that would be incredibly time consuming. Is there any way to make the imageframe null if the file path leads nowhere?

    The error I'm getting right now is "Run-time error '2220': Microsoft Access can't open the file "file path"

  6. #6
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Try:

    If Len(Dir(Me![ImagePath1])) > 0 Then
    If IsNull(Me![ImagePath1]) Then
    Me![ImageFrame].Picture = ""
    Else
    Me![ImageFrame].Picture = Me![ImagePath1]
    End If
    End If

  7. #7
    dtbconfusion is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    7
    Hmmm with this I get "run-time error '13' Type mismatch"

    Thank you again for all the help--sorry you have to spoonfeed me! This is just so above my level.

  8. #8
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Put breakpoint on first line and see what Len(Dir(Me![ImagePath1])) is. Seems like that is the error line right?

  9. #9
    dtbconfusion is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    7
    Click image for larger version. 

Name:	Capture.PNG 
Views:	18 
Size:	6.1 KB 
ID:	25548

    Yes, that is the error line! Am I doing this correctly?

  10. #10
    Bulzie is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Umm not sure, maybe someone else might have suggestion.

    Try replacing Me![ImagePath1] with the actual path to see if it works. So like:
    If Len(Dir("c:\MyFolder\Myfile") > 0

    What does the typical path string actually look like?

  11. #11
    dtbconfusion is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2016
    Posts
    7
    No, that doesn't work either. I think I'm just going to clear all the non-existent photos from the table...I guess it doesn't really make sense to have paths that go nowhere in the table.

    Thank you for all the help!

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I would declare a string and then assign the value of the field to the string.


    Maybe something like ...
    Dim strPath as string
    strPath = ""

    If not isnull(Me![FieldName])
    strPath = Me![FieldName]
    End if

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 06-23-2016, 05:09 PM
  2. Replies: 11
    Last Post: 05-15-2016, 07:38 AM
  3. Finding photos in network based on photo tags
    By LonghronJ in forum Modules
    Replies: 1
    Last Post: 02-18-2016, 04:02 PM
  4. photos
    By nashr1928 in forum Forms
    Replies: 4
    Last Post: 11-19-2010, 11:56 PM
  5. Tabs and Photos
    By Nixx1401 in forum Forms
    Replies: 1
    Last Post: 07-19-2010, 02:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums