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. Anonymous
    2023-03-14T21:36:38+00:00

    Private Sub OpenImageBtn_Click(Cancel As Integer)

    Hi Walt,

    The Click event has no Cancel argument, so try:

    Private Sub OpenImageBtn_Click()

    It is the DblClick event that has the Cancel argument.

    Imb.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-03-14T19:57:39+00:00

    Only the Click is used.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-03-14T19:56:42+00:00

    Scott,

    I entered the following code:

    Private Sub OpenImageBtn_Click(Cancel As Integer)

    Application.FollowHyperlink Me.DigitalFileName

    If Dir(Me.DigitalFileName) = "" Then

    MsgBox "File doesn't exist" 
    

    Else

    Application.FollowHyperlink Me.DigitalFileName 
    

    End If

    End Sub

    When I tried to open the search form I was asked for a Parameter. Also when in Code View, I tried to use the run button in the Debug Tool Bar and a popup box appeared asking for a Macro. I've done something wrong that i don't see.

    Walt

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-03-13T23:53:41+00:00

    You need to use DIR to check if the file exists

    If DIR(Me.DigitalFilename) = "" Then

    MsgBox "File doesn't exist"

    Else

    Application.Followhyperlink Me.DigitalFilename

    End If

    Make sure you don't use both the Click and double click events, just us the Click event.

    Was this answer helpful?

    0 comments No comments
  5. 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