Insert and delete link tables using vba (1 Viewer)

jack1234

Registered User.
Local time
Today, 05:18
Joined
Jun 2, 2007
Messages
16
I have two table which is c:\db1.mdb; c:\db2.mdb

The user is currently using c:\main.mdb
In main.mdb, I have a form, and have a combobox with two value, which is db1.mdb and db2.mdb.

If the user choose db2.mdb, delete all the current db1.mdb link tables(if there is any), and import all the tables from db2.mdb as link table
If the user choose db1.mdb, delete all the current db2.mdb link tables(if there is any), and import all the tables from db1.mdb as link table

And I need to perform some vba on the afterUpdate event of combobox.

My question is, how to
1)delete all link tables using vba
2)Import all tables from a certain mdb file as linked table using vba?
 

freakazeud

AWF VIP
Local time
Today, 09:18
Joined
Sep 10, 2005
Messages
221
re:

Hi,
for the deleting part either use the DeleteObject method of the DoCmd object or the SQL DDL drop statement in a loop.
For the second part again use a loop with the TransferDatabase() method to link the new external tables. You obviously first would need to extract the names of the external tables so you can pass them along in the source argument of the TransferDatabase() method in your loop.
HTH
Good luck
 

Users who are viewing this thread

Top Bottom