Update reference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Nikos

I have several of mdb's, working with reference between them.
And I'm working with three areas
Dev, Qa, Prod
I want to have another mdb, and with a click of a button to change the link
of the tables, queries, reference, and the property of all selected mdb's.
I know how to link the tables and the queries, but I dont know how to
change the path to the reference mdb in a remote mdb using vba.
 
Ofer,

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

Nikos
 
Back
Top