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: The LocateFile() function does not work properly if your computer runs only the Runtime version of Microsoft Access 2002.
REFERENCES
For more information about using Visual Basic for Applications code tosearch for files, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type filesearch object in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Additional query words: acc2000, Acc2002
Keywords: kbprogramming kbhowto kbinfo KB210613