• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

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=" & ???????
      End If

MsgBox "Tables Relinked"

End Function
1 Solution
Rey Obrero (Capricorn1)Commented:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
For more options see my article:

How to Manage Your Linked Tables
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now