Microsoft KB Archive/210613

= How to find the location or locations of a file in Microsoft Access =

Article ID: 210613

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210613





For a Microsoft Access 97 version of this article, see 171193.

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
This article describes how to create a sample user-defined function that uses the FileSearch object contained in the Application object to locate a file on a particular drive.



MORE INFORMATION
The LocateFile function takes the file that you are looking for as a string argument and returns all locations of that file. To create this function, follow these steps:  Start Microsoft Access, and then create a new database. Create a module, and then type the following line in the Declarations section if it is not already there:

Option Explicit

  Type the following procedure in the module sheet: Function LocateFile(strFileName as String) Dim vItem As Variant With Application.FileSearch .FileName = strFileName .LookIn = "C:\" .SearchSubFolders = True .Execute For Each vItem In .FoundFiles Debug.Print vItem Next vItem End With End Function  To test this function, type the following line in the Immediate window, and then press ENTER:

?LocateFile("Northwind.mdb")

Note that all locations of Northwind.mdb are printed in the Immediate window.

Note: The LocateFile function does not work properly if your computer runs only the Runtime version of Microsoft Access 2002.

