tags:

views:

622

answers:

3

I have a ms-access database and several ODBC linked tables in it.

As I have 2 set of ODBC database ,one is for production the other is for development, they have different names Development and Production.

How can I get the odbc info of the linked tables by using VBA?

A: 

Using the local name of the table, you can query the MSysObjects system table (typically hidden) for the table's Foreign Name.

SELECT MSysObjects.ForeignName
FROM MSysObjects
WHERE (((MSysObjects.Name)="LocalTableName"));

If you need more information about the foreign table, try your hand at parsing the 'Connect' column from the same table.

David Walker
Using system tables are officially unsupported, therefore arguably unsafe e.g. they may change in a future version. I tried this on an Access2007 ACE .accdb file and got and error, "Record(s) cannot be read; no read permission on 'MSysObjects'." Considering user level security has been removed for the .accdb format, is there a workaround at all?
onedaywhen
I tried that query with Access2007 and a 2003 MDB which includes a linked table from another 2003 MDB. As David indicated, ForeignName holds the name of the source table. However, the Connect column is blank. But there is another column, "Database", which contains the full path to the backend MDB where the source table resides.
HansUp
A: 

In fact, you can use ODBC to connect to the .mdb file as if it were an Access database. The linked tables will show up in that ODBC connection and be accessible at full ODBC speeds.

The nice thing about doing it that way is your program doesn't even have to know if the tables are linked tables or not. It's nice to contain all these sysadmin-level details in a single place.

apenwarr
A: 

Since you mentioned using VBA to retrieve information, I'll suggest the TableDef object.

You can determine the remote database where the source table resides:

CurrentDB.TableDefs("YourLinkedTableName").Connect

You can determine the name of the remote table to which your link points:

CurrentDB.TableDefs("YourLinkedTableName").SourceTableName

Beyond that, I'm not clear about what information you're looking for.

HansUp