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