ACC1x: How to Find Attached Table's Database Name

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
Issue type : kbhowto


Last Reviewed: April 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.