As a result of another thread, I had this idea. I'm not even sure how one might apply it, but thought I'd post it for you to decide.
This sub accepts the path and name of an Access database as a parameter and links the tables in the external database without having to specifically name the tables.
This sub accepts the path and name of an Access database as a parameter and links the tables in the external database without having to specifically name the tables.
Code:
Public Sub LinkIt(strDB As String)
' links tables from another db
' sub parameter is string format of path & name of DB
Dim db As Database, strTable As String
Dim i As Integer
Set db = DBEngine.Workspaces(0).OpenDatabase(strDB)
db.TableDefs.Refresh
For i = 0 To db.TableDefs.Count - 1
strTable = db.TableDefs(i).Name
' skip linking of system tables
If Left(strTable, 4) <> "msys" Then
DoCmd.TransferDatabase acLink, "Microsoft Access", strDB, acTable, strTable, strTable
End If
Next i
Set db = Nothing
End Sub