ACC1x: How to Find Attached Table's Database Name

Last reviewed: June 8, 1997
Article ID: Q109725
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1

SUMMARY

This article describes how to use the FindFirst method on a dynaset of the MSysObjects table to find the path and filename of the database that contains an attached table.

Notes

  • The technique described below relies on the use of system tables stored with your database. These tables are undocumented and are subject to change in future versions of Microsoft Access.
  • This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual.

MORE INFORMATION

The following example demonstrates how to use the FindFirst method to find the path and filename of the database that contains an attached table:

  1. Create a new database.

  2. From the File menu, choose Attach Table.

  3. Select Microsoft Access in the Data Source box and then choose OK.

  4. Select the sample database NWIND.MDB in the File Name box and then choose OK.

  5. Select Categories in the Tables In NWIND.MDB box and then choose Attach. Choose OK, and then choose Close.

  6. Create a new module with the following sample code:

          '********************
          ' MODULE DECLARATIONS
          '********************
          Option Explicit
    

          Function AttachedDBName (TableName As String)
    
             Dim DB As Database
             Dim DS As Dynaset
    
             Set DB = CurrentDB()
    
             Set DS = DB.CreateDynaset("MSysObjects")
             DS.FindFirst "[name] = '" & TableName & "'"
    
             If Not DS.NoMatch Then
                AttachedDBName = DS![database]
             Else
                AttachedDBName = ""
             End If
    
          End Function
    
    

  7. To run the function, type the following in the module's Immediate window and press ENTER:

          ? AttachedDBName("Categories")
    

    Note that the function returns the path and filename of the database that contains the attached table.

REFERENCES

Microsoft Access "User's Guide," versions 1.0 and 1.1, Chapter 4, "Importing, Exporting, and Attaching," pages 60-72


Keywords : kbprg PgmObj
Version : 1.0 1.1
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


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: June 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.