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:
- Open the sample database NWIND.MDB.
- Attach the Examples table from the sample database SOLUTIONS.MDB. (The
SOLUTIONS.MDB database file is usually in the SAMPAPPS subdirectory.)
- 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
- From the View menu, choose Immediate Window.
- 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.