I would like to link tables between two databases using VBA code. I have two databases, Target.accdb and SharedTables.accdb. The following code is in my Target.accdb. I have them linked manually now but when I change the location of the two databases the link to shared doesn't change. I believe the following code will work but can't get the "td.connect" - string to work. I want this to link all tables in the target.accdb to the same table names in the sharedtables.accdb that are always in the same directory.
Dim td As DAO.TableDef
Dim tdnames As String
Dim strFilePath As String
Dim strSharedFiles As String
strFilePath = CurrentProject.Path
strSharedFiles = "SharedTables.accdb"
For Each td In CurrentDb.TableDefs
If Len(td.Connect) > 0 Then
td.Connect = ";DATABASE=" & ???????
MsgBox "Tables Relinked"