Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q210613
For a Microsoft Access 97 version of this article, see 171193 (http://support.microsoft.com/kb/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).

For a Microsoft Access 97 version of this article, see 171193 (http://support.microsoft.com/kb/171193/ ) .

↑ Back to the top


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.

↑ Back to the top


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:
  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
          .Execute
          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:
    ?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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB210613, kbinfo, kbhowto, kbprogramming

↑ Back to the top

Article Info
Article ID : 210613
Revision : 5
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 323