How to check if file exists

Randix

Registered User.
Local time
Today, 20:28
Joined
Mar 24, 2001
Messages
56
I've a button on an Access (97 version) form that starts Word and pulls up a particular Word document...how do i first check to see if the file exists before running the event?
 
Copy this function to a module:

'***************** Code Start *******************
'Check to see if a File exists
'
Function fIsFile(stPath As String) As Boolean
'Fully qualify stPath
'To check for a file example
' fIsFile("C:\FolderName\FileName.doc")
'
On Error Resume Next
fIsFile = Len(Dir(stPath)) > 0
End Function
'***************** Code End *********************

Here is an example of usage:

If fIsFile("C:\YourFileName.txt") Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

HTH
RDH
 

Users who are viewing this thread

Back
Top Bottom