Microsoft KB Archive/109725

{|
 * width="100%"|

ACC1x: How to Find Attached Table's Database Name

 * }

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.

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:

 Create a new database. From the File menu, choose Attach Table. Select Microsoft Access in the Data Source box and then choose OK. Select the sample database NWIND.MDB in the File Name box and then choose OK. Select Categories in the Tables In NWIND.MDB box and then choose Attach. Choose OK, and then choose Close.  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  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.</ol>