FredixBlog


Just my log about anything I could find enjoyable.



Archive for June, 2004

Check if file exists

author Posted by: fredometro on date Jun 3rd, 2004 | filed 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

Random Posts