Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA in Access to see if an external file exists? 1

Status
Not open for further replies.

VoodooRage

Programmer
Joined
Oct 9, 2002
Messages
43
Location
US
Is there anyway using VBA to check to see if an external file exists in a location. If I am not mistaken there was and "EXIST" function in VB5 you could use to determine if a file existed at a given location.

By the way, this site/forum is really FANTASTIC and very, very, HELPFUL. Thanks for everything everyone.

Lewis Akers
 
Use the Dir function:

If dir(&quot;C:\YourFileHere.txt&quot;) <> &quot;&quot; then the file exists.

If it returns &quot;&quot; then the file does exist.

You can also use the function to scroll through all files that match a certain pattern.
Pat B
 
I have a need to see if a file exists, and if so, kill it - you could probably adapt that code to do what you want...


Code:
With Application.FileSearch
    .NewSearch
    .LookIn = &quot;C:\&quot;
    .SearchSubFolders = False
    .FileName = &quot;MyFile.txt&quot;
    .MatchTextExactly = True
End With


With Application.FileSearch
    If .Execute() > 0 Then
        'The file must exist - do what you gotta do!
    End If
    
End With
 
Thanks a bunch everyone!

Problem solved again by you guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top