Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

【access小品】后台数据库重联函数

时 间:2010-05-29 00:00:00
作 者:todaynew   ID:10802  城市:武汉
摘 要:后台重联函数
正 文:

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

 



Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助