Update reference

O

Ofer

How can change the path of the reference in another DB.
Let say I have MDB1 open, now by using code I want to change the path of the
reference in MDB2 that have reference to MDB3

Again,
MDB2 has reference to MDB3 that placed in c drive, now using code in MDB1 I
want to change the path to D drive

Thanks for your help
 
N

Nikos Yannacopoulos

Ofer,

This will change all your linked tables from C to D:

Function change_links()
Dim db As DAO.Database
Dim tbl As DAO.TableDef

Set db = CurrentDb()
cp = "C:\"
np = "D:\"

For i = 0 To db.TableDefs.Count - 1
tbln = db.TableDefs(i).Name
Set tbl = db.TableDefs(tbln)
lnk = tbl.Connect
If Left(lnk, 9) = ";DATABASE" Then
lnk = Replace(lnk, cp, np)
tbl.Connect = ""
tbl.Connect = lnk
tbl.RefreshLink
End If
Next

End Function

It doesn't have o be just the drive, it might just as well be:
cp = "C:\SomeFolder\SomeFile.mdb"
np = "D:\AnotherFolder\AndASubfolder\SomeOtherFile.mdb"
or whatever. Just make sure you have an appropriate DAO reference.

HTH,
Nikos
 
N

Nikos Yannacopoulos

Ofer,

I'm sorry, I misinterpreted the question. What do you mean by
"references"? Connection strings in VBA code maybe?

Nikos
 

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