ACC2: How to Retrieve Path of an Attached MS Access 2.0 TableID: Q116146
|
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.
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:
'***************************************************************
' 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
For more information about the Connect property, search for "Connect," and then "Connect Property (Data Access)" using the Microsoft Access Help menu.
Keywords : kbinterop kbprg IsmIea
Version : 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 3, 1999