Open Photographs in an Access Form

Anonymous
2023-01-26T23:26:10+00:00

I have a datatbase of photograph file names. In the DB I have a List Form that has a "Digital File Name" field. Question: Is it possable to create a command button on my List Form that will open the photo (that is stored in my Photos File on my C: drive) based on the digital file name for the selected record?

I am using Access 2016

Thanks Walt

Microsoft 365 and Office | Access | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

49 answers

Sort by: Most helpful
  1. Anonymous
    2023-03-13T22:45:40+00:00

    Scott

    I have finally wised up and gone back and added the full path, which as you pointed out simplifies everything. The code you first showed me works perfectly and, with the full paths allows me to use as many image storage files as I like.

    I have run into a problem when trying to add an error trap. This is what I used:

    Private Sub OpenImageBtn_DblClick(Cancel As Integer)

    Application.FollowHyperlink Me.DigitalFileName

    If Application.FollowHyperlink = "" Then

        MsgBox "File does not exist"

    Else

        Application.FollowHyperlink Me.DigitalFileName

    End If

    End Sub

    I have something wrong as this code won't open the image. Also when I tried to change to a single click with the original code it also won't open the image.

    Private Sub OpenImageBtn_Click(Cancel As Integer)

    Application.FollowHyperlink Me.DigitalFileName

    End Sub

    Please straighten me out.

    Walt

    Was this answer helpful?

    0 comments No comments
  2. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-03-10T14:03:11+00:00

    I mentioned a while back why are you using the Double click event? Normally you use the click event of a command button.

    When you type in Me. Intellisense should present a list of objects to choose from. Make sure you chose the correct controlname.

    If that code is not working and nothing happens, you need to Step through the code and try to figure out what is happening. My book describes how to debug a routine by stepping through code.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-03-09T22:19:51+00:00

    Scott,

    I see what you were getting at, just didn't know how to do it. this is what I entered:

    Private Sub OpenImageBtn_DblClick(Cancel As Integer) {THIS LINE TURNED YELLOW}

    Dim strFile1 As String, strFile2 As String, strFile As String

    strFile1 = "D:\Documents\Family Tree Maker\Wright-Jagoe Media" & Me.digitialfilename       {THE .digitalfilename TURNED BLUE}
    
    strFile2 = "D:\Documents\Family Tree Maker\Laidlaw-WL Media" & Me.DigitalFileName 
    

    If Dir(strFile1) <> "" Then

    strFile = strFile1 
    

    Else IF DIR(strFile2) <> "" Then {THIS LINE TURNED RED}

    strFile = strFile2 
    

    Else

    MsgBox "File not found" 
    
    Exit Sub 
    

    End If

    Application.FollowHyperlink strFile

    End Sub

    I capitalized the DigitalFileName in strFile1 and the Blue went away. However when I Dbl clicked the Open Imabe Btn it did not open the selected image. I must have done something wrong.

    Lastly, you asked why I didn't store the full path with the file name. Only because I have a couple of thousand files in each of the two directories and couldn't figure out how to copy the path so I could paste it into my data entry form. If there is an efficient way to do it, I would go back and use the full path.

    Walt

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-03-09T20:34:52+00:00

    Your original request was create a command button on my List Form that will open the photo (that is stored in my Photos File on my C: drive) based on the digital file name

    As I've said, you can avoid the whole issue of having photos in 2 folders by storing the path with the filename.

    But since you don't, you have to find what folder the file is in. So your first task is to find the folder.

    Dim strFile1 As String, strFile2 As String, strFile As String

    strFile1 = "Path1" & Me.digitialfilename

    strFile2 = "Path2" & Me.digitalFilename

    If DIR(strFile1) <> "" Then

     strFile = strFile1
    

    Else IF DIR(strFile2) <> "" Then

     strFile = strFile2
    

    Else

     MsgBox "Filen not found"
    
     Exit Sub
    

    End If

    Application.FollowHyperlink strFile

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2023-03-09T19:02:24+00:00

    Scott,

    I think I understand what you're telling me is missing. What I don't know is what value to assign to strFile varible and how to write it. I have tried very combination I can think of, but the code isn't accepted. I hope I can find that in your book.

    Walt

    Was this answer helpful?

    0 comments No comments