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-01T18:23:50+00:00

    An image cannot be in both folders.

    there is nothing else in the record that would indicate which folder contains the image.

    There is no reason for a file name to be in a record if the image is not in either folder.

    As the file can only be in one of two folders it is easy to return the correct full path with an expression like that below, illustrated here in the immediate window on my system:

    FileName = TestBed.accdb

    ? IIf(Dir("C:\Users\kenws\Documents\Databases\TestBed" & FileName)<>"","C:\Users\kenws\Documents\Databases\TestBed" & FileName,"C:\Users\kenws\Documents\Databases\SomeOtherFolder" & FileName)

    Which correctly returns:

    C:\Users\kenws\Documents\Databases\TestBed\Testbed.accdb

    Whereas with:

    FileName = "SomeOtherFile.accdb"

    The same expression correctly returns:

    C:\Users\kenws\Documents\Databases\SomeOtherFolder\SomeOtherFile.accdb

    The expression should only be called If Not IsNull(FileName) of course to allow for records with no FileName value.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-03-01T16:43:11+00:00

    Answers:

    There is no real reason that stored only the file name and not the entire path. I see where you're going. If I stored the path then there is no requirement for more code as the search would go to the appropriate folder automatically. however, for several thousand images, it's alot more typing.

    These are the only two folders.

    An image cannot be in both folders.

    there is nothing else in the record that would indicate which folder contains the image.

    There is no reason for a file name to be in a record if the image is not in either folder.

    Walt

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-03-01T00:07:34+00:00

    When you say something doesn't work, you need to explain why and how it doesn't work. But I do see the problem. Look at the code. At the end you are trying to open strFile. Do you define strFile anyplace?

    So, lets backtrack a bit. This was your initial request; "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?"

    So, some questions

    In the record it appears you just store the filename and not the full path? Why?

    Are the 2 folders the only ones you store media in?

    Could the image file exist in both folders?

    Is there something else in the record that might indicate what folder the file is in?

    Why would a filename be added to a record when the file is not in a folder?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-02-28T22:54:44+00:00

    Here's what I tried that has something I did wrong as it doesn't work.

    Private Sub OpenImageBtn_DblClick(Cancel As Integer)

    Dim strFile As String

    strFile1 = "D:\Documents\Family Tree Maker\Wright-Jagoe Media" & Me.DigitFileName1

    strFile2 = "D:\Documents\Family Tree Maker\Laidlaw-Fowler Media" & Me.DigitFileName2

    If Dir(strFile1) = "" Or Dir(strFile2) = "" Then

    MsgBox "File does not exist!"

    Else

    Application.FollowHyperlink strFile

    End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  5. ScottGem 68,840 Reputation points Volunteer Moderator
    2023-02-28T21:38:17+00:00

    Scott, I am really confused being less than a beginner with code. I'm not sure which "three lines" are the ones you suggested.

    Could you please show me how the code should look?

    OK, this was the original code I suggested:

    Private Sub OpenImageBtn_DblClick(Cancel As Integer)

    Dim strFile as String

    strFile = "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media" & Me.DigitFileName

    If DIR(strFile) = "" Then

    MsgBox "File does not exist!"

    Else

    Application.FollowHyperlink strFile

    End If

    End Sub

    You then said that you had photos in 2 folders and asked how to deal with it. So I posted just the lines that needed to be changed.

    strFile1 = "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media" & Me.DigitFileName1

    strFile2 = "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media" & Me.DigitFileName2

    If DIR(strFile1) = "" OR DIR(strFile2) = "" Then

    You have to use the whole code not just the modified lines.

    Was this answer helpful?

    0 comments No comments