|
本帖最后由 todaynew 于 2010-5-28 16:25 编辑
Function MyTrdb(Fname As String)
'功能:重建表链接。
'参数:Fname:后台数据库完整文件名
'示例:MyTrdb(CurrentProject.Path & "\后台数据库.mdb")
Dim obj As AccessObject, dbs As Object
Dim tbnmae As String
On Error GoTo MyTrdb_Err
Set dbs = Application.CurrentData
For Each obj In dbs.AllTables
tbnmae = obj.Name
If InStr(obj.Name, "MSys") = 0 Then
DoCmd.DeleteObject acTable,tbnmae '删除链接
DoCmd.TransferDatabase acLink, "Microsoft Access", Fname, acTable, tbnmae, tbnmae, False '建立链接
End If
Next obj
MyTrdb_Exit:
Exit Function
MyTrdb_Err:
MsgBox Error$
Resume MyTrdb_Exit
End Function
可在for each中加if语句,以实现特定表的链接。 |
|