Changing the source of linked tables

M

Milan

Hello,

I have this problem. I have to change a source (connection string) of
linked tables using VBA. All the tables are of MS Jet type. I tried to
do it this way:

-------
CurrentDb.TableDefs("X").Connect = "MS
Access;PWD=xxx;DATABASE=C:\DB\Y.mdb;TABLE=X"

CurrentDb.TableDefs("X").RefreshLink
-------

but the source was not changed and no msgbox with error description
displayed. I use Access XP.

Thank you very much for your help.

Milan
 
M

Marshall Barton

Milan said:
I have this problem. I have to change a source (connection string) of
linked tables using VBA. All the tables are of MS Jet type. I tried to
do it this way:

-------
CurrentDb.TableDefs("X").Connect = "MS
Access;PWD=xxx;DATABASE=C:\DB\Y.mdb;TABLE=X"

CurrentDb.TableDefs("X").RefreshLink

FIrst, you need to use an object variable for the database
objecy. Every use of the CurrentDb() function creates a new
copy of the db object and your TableDef goes out of scope as
soon as the statement finishes executing.

The connect string is not that complicated. Try this:

Set db = CurrentDb()
Set tdf = db.TableDefs("X")
tdf.Connect = ";DATABASE=C:\DB\Y.mdb"
tdf.RefreshLink
Set tdf = Nothing
Set db = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top