|
本帖最后由 todaynew 于 2010-12-20 11:36 编辑
roych 发表于 2010-12-20 01:28
回复 todaynew 的帖子
如果能自动更新链接表就好了~~我解压放在桌面后每次都弹出这个对话框,然后除了浏览 ...
用以下函数处理:
Function MyTrdb(Fpath As String, Fname As String)
'引用:Microsoft Scripting Runtime
'功能:重建表链接。
'参数:Fname:后台数据库完整文件名
'示例:MyTrdb(CurrentProject.Path & "\","后台.mdb")
Dim myFSO As New FileSystemObject
Dim obj As AccessObject, dbs As Object
Dim tbnmae As String, sname As String
Dim Dname As String
On Error GoTo MyTrdb_Err
If myFSO.FileExists(Fpath & Fname) = True Then
Set dbs = Application.CurrentData
For Each obj In dbs.AllTables
If InStr(obj.Name, "MSys") = 0 Then
If DLookup("Type", "MSysObjects", "name='" & obj.Name & "'") = 6 Then
Dname = Nz(DLookup("Database", "MSysObjects", "name='" & obj.Name & "'"), "")
If Fpath & Fname <> Dname Then
If Dname <> "" Then
If Mid(Dname, InStrRev(Dname, "\") + 1) = Fname Then
tbnmae = obj.Name
sname = DLookup("ForeignName", "MSysObjects", "name='" & obj.Name & "'")
DoCmd.DeleteObject acTable, tbnmae '删除链接
DoCmd.TransferDatabase acLink, "Microsoft Access", Fpath & Fname, acTable, sname, tbnmae, False '建立链接
End If
End If
End If
End If
End If
Next obj
End If
MyTrdb_Exit:
Exit Function
MyTrdb_Err:
MsgBox Error$
Resume MyTrdb_Exit
End Function
一楼的实例已经更新,请参见该函数的用法。 |
|