Function LinkTables(dbPath As String) As Boolean
'This links to all the tables that reside in DbPath,
' whether or not they already reside in this database.
'This works when linking to an Access .mdb file, not to ODBC.
'This keeps the same table name on the front end as on the back end.
Dim rs As Recordset
Dim stsql As String
stsql = "SELECT Name " & _
"FROM MSysObjects IN '" & dbPath & "' " & _
"WHERE Type=1 AND Flags=0"
On Error Resume Next
'get tables in back end database
If InStr(dbPath, "BackEndDb.accdb") > 0 Then
stsql = stsql & " AND left(Name,6) <> 'mSPLIT'"
End If
Set rs = CurrentDb.OpenRecordset(stsql)
If Err <> 0 Then Exit Function
'link the tables
While Not rs.EOF
'delete old link, assuming front and back end table have the same name
DoCmd.DeleteObject acTable, rs!Name
'make new link
DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, rs!Name, rs!Name
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
LinkTables = True
End Function