在Autoecex中调用以下函数:
Function MyTrdb(Fname As String)
'功能:重建表链接。
'参数:Fname:后台数据库完整文件名
'示例:MyTrdb(CurrentProject.Path & "\后台数据库.mdb")
Dim obj As AccessObject, dbs As Object
Dim tbname As String
On Error GoTo MyTrdb_Err
Set dbs = Application.CurrentData
For Each obj In dbs.AllTables
tbname = obj.Name
If InStr(obj.Name, "MSys") = 0 Then
If DLookup("Database", "MSysObjects", "Type=6 AND Name='" & obj.Name & "'") <> Fname Then
DoCmd.DeleteObject acTable, tbname '删除链接
DoCmd.TransferDatabase acLink, "Microsoft Access", Fname, acTable, tbname, tbname, False '建立链接
End If
End If
Next obj
MyTrdb_Exit:
Exit Function
MyTrdb_Err:
MsgBox Error$
Resume MyTrdb_Exit
End Function