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: Oldest
  1. 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
  2. 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
  3. Anonymous
    2023-03-14T19:57:39+00:00

    Only the Click is used.

    Was this answer helpful?

    0 comments No comments
  4. 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
  5. Anonymous
    2023-04-21T21:22:51+00:00

    I am trying to include an error trap with my "Open Image Button" so that when searched and no digital image file is found a message box will come up with "File does not exist".

    The following is the code I have entered:

    Private Sub OpenImageBtn_Click()

    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 click the "Open Image Button" the message box don't appear and the image is opened twice. Can anyone tell me what's wrong with this code.

    Thanks, Walt

    Was this answer helpful?

    0 comments No comments