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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read location of BE? 1

Status
Not open for further replies.

VictoryHighway

Technical User
Mar 4, 2004
115
0
0
US
Greetings,
Is there a way to write a code in VBA to locate the back end of the database and store that as a string?

Thanks in advance,
Geoffrey
 
Well, you can do it by querying MSysObjects - let's say you have an attached table called MyAttachedTable.

Query MSysObjects thus to return the path of the table the attached table comes from:
Code:
SELECT Database FROM MSysObjects WHERE Name='MyAttachedTable' AND Type IN (4,6)

It doesn't take much to see how you could embed this type of query in your code, I hope.

[pc2]
 
There is not necessarily "a" back end. The front end database can link tables from multiple back ends in any combination. So you have to think of it as a back end with respect to a given table.

The technique I use is to access the table's TableDef object (DAO) and then get the Connect property. This property returns a string that contains text like ";DATABASE=xxxxxxxxx" followed by either a ";" or the end of the string. The "xxxxxxx" will be the full path of the .mdb file containing the table, which is what you want.

I don't like using MSysObjects, because its content (even its structure) is undocumented.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top