Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/210613

From BetaArchive Wiki
Knowledge Base

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

Article ID: 210613

Article Last Modified on 10/11/2006


  • 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).


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.


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:

  1. Start Microsoft Access, and then create a new database.
  2. Create a module, and then type the following line in the Declarations section if it is not already there:

    Option Explicit

  3. 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
          For Each vItem In .FoundFiles
             Debug.Print vItem
          Next vItem
       End With
    End Function
  4. To test this function, type the following line in the Immediate window, and then press ENTER:


    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.


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