Help and Support
 

powered byLive Search

ACC2: How to Retrieve Path of an Attached MS Access 2.0 Table

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:116146
Last Review:November 6, 2000
Revision:1.0
This article was previously published under Q116146

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes a sample user-defined Access Basic function that you can use to retrieve the path and filename of the originating database for an attached Microsoft Access table. The function uses the attached table's Connect property to get this information.

Back to the top

MORE INFORMATION

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 "Building Applications" manual.

The following example demonstrates how to create and use the sample GetAttachedDBName() function:
1.Open the sample database NWIND.MDB.
2.Attach the Examples table from the sample database SOLUTIONS.MDB. (The SOLUTIONS.MDB database file is usually in the SAMPAPPS subdirectory.)
3.Create a new module and enter the following code.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.
      '***************************************************************
      ' Declarations section of the module.
      '***************************************************************

      Option Explicit

      '===============================================================
      ' The GetAttachedDBName() function requires the name of an
      ' attached 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 GetAttachedDBName (TableName As String)
         Dim db As Database, Ret
         On Error GoTo DBNameErr
         Set db = DBEngine.Workspaces(0).Databases(0)
         Ret = db.TableDefs(TableName).Connect
         GetAttachedDBName = Right(Ret, Len(Ret) - (InStr_
            (1, Ret, "DATABASE=") + 8))
         Exit Function
      DBNameErr:
         GetAttachedDBName = 0
      End Function
						
4.From the View menu, choose Immediate Window.
5.In the Immediate window, type the following line and then press ENTER:

? GetAttachedDBName("Examples")
The path of the attached table's originating database will be displayed in the Immediate window.

Back to the top

REFERENCES

For more information about the Connect property, search for "Connect," and then "Connect Property (Data Access)" using the Microsoft Access Help menu.

Back to the top


APPLIES TO
Microsoft Access 2.0 Standard Edition

Back to the top

Keywords: 
kbhowto kbinterop kbprogramming KB116146

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.