ACC97: Sample Procedure to Find the Location(s) of a File

Last reviewed: July 10, 1997
Article ID: Q171193
The information in this article applies to:
  • Microsoft Access 97

SUMMARY

Advanced: Requires expert coding, interoperability, and multi-user skills.

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

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.

MORE INFORMATION

The LocateFile() function takes the file you are looking for as a string argument and returns all locations of that file. To create the function, follow these steps:

  1. Open the sample database Northwind.mdb.

  2. Create a module and type the following line in the Declarations section if it is not already there:

          Option Explicit
    

  3. Type the following procedure:

          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 Debug window, and then press ENTER:

           ?LocateFile("northwind.mdb")
    

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

REFERENCES

For more information about using Visual Basic for Applications code to search for files, search the Help Index for "FileSearch object," and then click FoundFiles in the object tree at the top of the FileSearch Object Help topic.


Keywords : kbcode MdlGnrl
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.