marku24
asked on
Linking Tables in Access through VBA
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.
Function fncLinkTables()
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=" & ???????
td.RefreshLink
End If
Next
MsgBox "Tables Relinked"
End Function
Function fncLinkTables()
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=" & ???????
td.RefreshLink
End If
Next
MsgBox "Tables Relinked"
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How to Manage Your Linked Tables