Could anyone explain why the first code example works but the second doesn't?
This re-link code DOES work:
Dim db As Database
Dim sNewLinkAddress As String
sNewLinkAddress = "C:\temp\backend.accdb"
Set db = CurrentDb
db.TableDefs("table1").Connect = ";Database=" & sNewLinkAddress
db.TableDefs("table1").RefreshLink
This re-link code DOES NOT work, but no error messages are given:
Dim sNewLinkAddress As String
sNewLinkAddress = "C:\temp\backend.accdb"
CurrentDb().TableDefs("table1").Connect = ";Database=" & sNewLinkAddress
CurrentDb().TableDefs("table1").RefreshLink
What concerns me is that there is a fundamental difference that I'm unaware of between using the Database object directly returned by CurrentDB() and using a variable 'db' that is set to the Database object returned by CurrentDB(). To my mind both ways should be identical, but obviously I'm wrong!
In the past I have used CurrentDB() directly for various things such as opening a recordset with no problem. There seems to be a specific issue with re-linking tables. Any ideas to what's going on here?
I'm using access 2007, but the same issue applies to 2003 also.