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

Last reviewed: June 3, 1997
Article ID: Q116146
The information in this article applies to:
  • Microsoft Access version 2.0

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.

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.

REFERENCES

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


Keywords : IsmIea kbinterop kbprg PgmHowTo
Version : 2.0
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 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.