ledgerr.rob
Registered User.
- Local time
- Yesterday, 16:50
- Joined
- Jun 3, 2012
- Messages
- 68
Hello all
Access 2007
Windows Vista
I'm opening a pdf file that is external to the database and should always be located in the same directory. I have found the code that will open the file with a click event.
I need to include some error trapping presumably at the end of the code in case the file has been moved it will catch the mistake and say that the file is missing, etc... I know how to tell the machine to open a file, but I'm not sure how to tell the machine to look for the file first and if it there, open it.
As you can see i've hardcoded the name of the file into the code. This works but might be a better/more elegant way out there?
Thanks for any advice
rob
Access 2007
Windows Vista
I'm opening a pdf file that is external to the database and should always be located in the same directory. I have found the code that will open the file with a click event.
Code:
Private Sub btnFile_Click()
'use command button to open pdf file
'need to get path of database and add the file name
Dim strDBPath As String
Dim strFileName As String
'get the path of the database and assign to strDBPath
strDBPath = CurrentProject.Path
'Assign strDBPath and name of file to strFileName
strFileName = strDBPath & "\" & "File.pdf"
'implement error trapping to insure the file is in the proper place
'if it is in place, open the file
'if it is not advise the user to browse for? or move the file to? the proper place
Application.FollowHyperlink strFileName
End Sub
I need to include some error trapping presumably at the end of the code in case the file has been moved it will catch the mistake and say that the file is missing, etc... I know how to tell the machine to open a file, but I'm not sure how to tell the machine to look for the file first and if it there, open it.
As you can see i've hardcoded the name of the file into the code. This works but might be a better/more elegant way out there?
Thanks for any advice
rob