A family of Microsoft relational database management systems designed for ease of use.
My bad!!! It did work after I selected the correct image. Thank you, thank you for your help 🤠
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
A family of Microsoft relational database management systems designed for ease of use.
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.
My bad!!! It did work after I selected the correct image. Thank you, thank you for your help 🤠
Thanks for your help - I need all I can get. I first made sure that the field name had no spaces "DigitalFileName". I then changed the code to "
Private Sub OpenImageBtn_DblClick(Cancel As Integer)
Application.FollowHyperlink "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media\" & Me.DigitalFileName
End Sub
Saved everything and dbl clicked the command button and got this error message on the code builder page:
Run-time error '490':
Cannot open the specified file.
Somethings wrong!
In your code, "OpenImageBtn" refers only to the command button which you click. Instead, use the field in the table which actually contains the name of the actual image itself. It appears from your question that that field is named: "Digital File Name". Bind that field to a text box control on the form and change the reference in your code to that field.
By the way, we generally recommend field names should have no spaces in them. It should be "DigitalFileName", not "Digital File Name". It is a minor issue that can have major impact on your frustration level.
Scott,
Yes I tried your suggestions but was unable to get either one to work. It's probably that I'm not expert enough with Access to fully understand. I understand the events and put them in using event builder in the command box double click. I can't figure out how to bind the command button to the image field in my form as the command button data tab doesn't have a field option. Below is how I entered the event for an image entry using the full path in the inage field of my form:
Private Sub OpenImageBtn_DblClick(Cancel As Integer)
Application.FollowHyperlink Me.OpenImageBtn
End Sub
I also tried with only the file name entered in the image field:
Private Sub OpenImageBtn_DblClick(Cancel As Integer)
Application.FollowHyperlink "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media\" & Me.OpenImageBtn
End Sub
Not sure what I'm missing or doing wrong.
Walt
Hello
Thanks for the update.
You may want to include error handling in case the file is not found or the path is incorrect. You can use the On Error Resume Next statement to catch any errors and then use the On Error GoTo statement to handle them.
For example:
Private Sub cmdOpenFile_Click() On Error Resume Next 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
' Error handling If Err.Number <> 0 Then MsgBox "Error opening file. Please check the file name and path.", vbExclamation Exit Sub End If End Sub
This will display a message box if an error occurs while trying to open the file, allowing the user to check the file name and path.
It is also recommended to add a button caption to the button in the design view so the user knows what the button does.
Lastly, you can also add a filter to the file path if the user has a different file type other than the default one. This will ensure that the file opens in the correct application.
For example:
filePath = "C:\Photos" & filePath & ".jpg"
This will add .jpg to the file path, ensuring that the file opens in the correct application for jpeg files.
While the code you gave seems to have some typo error.
On this line:
Set fso = CreateObject("Scripting.FileSystemObject')
There is an extra single quote at the end of the string that should be removed. It should be:
Set fso = CreateObject("Scripting.FileSystemObject")
Also, please make sure that the directory "D:\Documents\Family Tree Maker\Wright-Jagoe(1) Media" exists and that the file name you have in the "Digital File Name" field matches the file name in the directory.
Another thing that you can do is to add a MsgBox command before the fso. GetFile(filePath). Open command, so that you can check the value of the filePath variable. This will help you to understand if the path is correct or not.
For example:
MsgBox filePath
This will display the filePath value in a message box, so you can see if it is what you expect.
Finally, you can also include error handling as I mentioned before, so that if the file is not found or the path is incorrect, a message box will be displayed, allowing the user to check the file name and path.
I hope this information helps.
Regards,
Abdal