Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about database name 1

Status
Not open for further replies.
Jun 1, 2006
58
US
Hi all,

Right now, I have this code in my VBA module. One of the columns in my tables is the name of the database.

Public Function CurrDB() As String
On Error Resume Next
Dim dbs As Database
Set dbs = CurrentDb
CurrDB = dbs.Name
End Function

But instead of the name of the database, I need the name of the database to which the linked tables are linked to. Can anyone tell me how to get that?

Thanks
 
The Connect property of a table contains the name of the linked database.

[tt]Dim tdf As TableDef
Set tdf=db.Tabledefs("tblT")
x=tdf.Connect[/tt]
 
I get an error saying invalid procedure call.

This is the code I have

Public Function CurrDB() As String
On Error Resume Next
Dim tdf As TableDef
Set tdf = db.TableDefs("name of my linked table")
x = tdf.Connect
CurrDB = x
End Function

Where am I going wrong?
 
The answer is contained in the Connect property, it is not all of the Connect property. You will also need to set db as equal to a database:

Code:
Public Function CurrDB() As String
On Error Resume Next
Dim tdf As TableDef
Set db = CurrentDb
Set tdf = db.TableDefs("name of my linked table")
X = tdf.Connect
Debug.Print X
End Function

X will look something like:
;DATABASE=C:\Docs\Tek-Tips.mdb

So you need:
Mid(X,11)
 
aspiringprog

There is also the MSysObjects table where Type=1 reffers to local tables. A simple query could give you an image.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top