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-01-29T00:18:09+00:00

    Did you try the suggestion I made?

    While Abdal's solution can work, it is using a cannon to swat a fly.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-01-28T23:28:07+00:00

    Abdal,

    Thank you for your reply. I tried the code you suggested and it would not work for me. When I clicked my Open Image command button nothing happened. Following is the code I wrote as copied from the Code bulider page of the Open Image command button:

    Private Sub cmdOpenFile_Click()

    Dim fso As Object 
    
    Dim filePath As String 
    

    'Get the value of the "Digital File Name" field

    filePath = Me![Digital File Name] 
    

    ' Construct the full file Path

    filePath = "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media" & filePath 
    

    ' Create a FileSystemObject

    Set fso = CreateObject("Scripting.FileSystemObject') 
    

    ' Open the file

    fso.GetFile(filePath).Open 
    

    End Sub

    I must have made some mistake as I am not to far advanced in Access, although I do follow directions pretty well.

    Hope you can help - Walt

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-01-27T14:22:19+00:00

    Sure, it real easy. I'm assuming here that the Digital File Name includes the full path and filename. So what I would do is use the Double click event of the control bound that field and use this code:

    Application.FollowHyperlink Me.txtFilename

    Where txtFilename is the name of the control bound to the field. This will open the fiel in your default photo editor.

    If you only store the filename and not the full path, you sould need to do something like:

    Application.FollowHyperlink "C:\photos" & Me.txtFilename

    Alternatively, you could simply add an unbound image control to the form and set the Controlsource to the field.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2023-01-27T01:19:24+00:00

    Hello

    I am Abdal and I would be glad to help you with your question.

    Yes, it is possible to create a command button on your List Form that opens the photo based on the digital file name for the selected record. You can use VBA (Visual Basic for Applications) code to accomplish this. The code would use the FileSystemObject to open the file and the value of the "Digital File Name" field to construct the file path. You can then assign the code to the On Click event of the command button. Here is an example of code that you could use to open the file:

    Private Sub cmdOpenFile_Click() Dim fso As Object Dim filePath As String

    ' Get the value of the "Digital File Name" field filePath = Me! [Digital File Name]

    ' Construct the full file path filePath = "C:\Photos" & filePath

    ' Create a FileSystemObject Set fso = CreateObject("Scripting.FileSystemObject")

    ' Open the file fso. GetFile(filePath). Open End Sub

    You would need to replace 'Digital File Name' with the name of your field and the 'C:\Photos' with the path of your photos directory.

    I hope this information helps.

    Regards,

    Abdal

    Was this answer helpful?

    0 comments No comments