Check if file exists
Posted by: fredometro on
Jun 3rd, 2004 |
Filed under: MS-Access
It is often needed to know wether or not a file exists.
This simple function will do the job.
For instance, if we need to delete a file if it exists:
If FileExists("c:\myfile.txt") Then
Kill "c:\myfile.txt"
End If
Here is the code of the function:
Public Function FileExists(FileName)
On Error Resume Next
Open FileName For Input As 1
If Err = 0 Then
FileExists = True
Close 1
Else
FileExists = False
End If
End Function

Be the first!
Tags: