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.

ACC2000: How to Retrieve the Path of Linked Microsoft Access Tables


View products that this article applies to.

This article was previously published under Q210062
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

↑ Back to the top


Summary

This article shows you how to create a sample user-defined Visual Basic for Applications function to retrieve the path and file name of the originating database for a linked Microsoft Access table. The function uses the linked table's Connect property to obtain this information.

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.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following example shows you how to create and use the sample GetLinkedDBName() function:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. On the File menu, point to Get External Data, and then click Link Tables. Link the Rooms table from the sample database Inventry.mdb, which is usually in the Samples folder.
  3. Create a new module, and then type the following procedure:
    '===============================================================
    ' The GetLinkedDBName() function requires the name of a
    ' linked Microsoft Access table, in quotation marks, as an
    ' argument. The function returns the full path of the originating
    ' database if successful, or returns 0 if unsuccessful.
    '===============================================================
    
    Function GetLinkedDBName (TableName As String)
       Dim db As DAO.Database, Ret
       On Error GoTo DBNameErr
       Set db = CurrentDb()
       Ret = db.TableDefs(TableName).Connect
       GetLinkedDBName = Right(Ret, Len(Ret) - (InStr _
          (1, Ret, "DATABASE=") + 8))
       Exit Function
    DBNameErr:
       GetLinkedDBName = 0
    End Function
    					
  4. To test this function, type the following line in the Immediate window, and then press ENTER:
    ? GetLinkedDBName("Rooms")
    Note that the path of the linked table's originating database is displayed in the Immediate window.
You can also check the path of a linked table by using the Linked Table Manager feature (on the Tools menu, point to Database Utilities, and then click Linked Table Manager).

↑ Back to the top


References

For more information about the Connect property, click Microsoft Visual Basic Help on the Help menu, type connect property in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: KB210062, kbprogramming, kbinfo, kbhowto

↑ Back to the top

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