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: Newest
  1. 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
  2. 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
  3. 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
  4. 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
  5. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-03-07T22:05:38+00:00

    In your last post, you said I didn't assign a value to the strFiles. I don't see what names could be assigned other than the two paths. I hope your book will clarify this.

    The problem is you assigned values to strFiles1 and strFiles2, but not strFiles. Each is a SEPARATE variable. I think that may be what you are missing. When you define a variable it has a null value. You have to assign a value to use it. In your code you assign values to strFiles1 and strFiles2, but then you don't use those variables. You use strFiles.

    Was this answer helpful?

    0 comments No comments