是否可以在Access 2003中查询链接表管理器?

时间:2012-08-23 14:28:58

标签: ms-access-2003 linked-tables

我有一个数据库目录(* .mdb),它链接到其他位置的其他几个* .mdb。

我们将原始数据库从一个文件拆分为两个分区。目录中的数据库指向原始数据库文件(以及其他一些数据库)。现在我需要将目录中每个数据库的表重新链接到原始(现在拆分)数据库的正确分区。

我一直在手动重新链接每个数据库的链表管理器中的表,但这非常低效,如果我能以某种方式查询链接表管理器,我可以很容易地发现我是否已经更改正确的表格数量。

有没有办法查询链接表管理器?通过VB甚至使用系统表和SQL使用表名和文件位置?

注意我在MS Access 2003中打开文件,但MS Access 2003正在打开它们并报告Access 2000格式。

Per Remou的建议是我写的一些代码重新链接表格:

Sub RelinkLinks()
    Dim db As Database
    Dim tdf As TableDef

    Dim OldLoc As String
    OldLoc = ";DATABASE=\\lois\_DB\DB\BE.mdb"

    Dim partition1Loc As String
    Dim partition2Loc As String
    partition1Loc = ";DATABASE=\\lois\_DB\DB\Partition 1\BE.mdb"
    partition2Loc = ";DATABASE=\\lois\_DB\DB\Partition 2\BE.mdb"

    Set db = CurrentDb

    For Each tdf In db.TableDefs

        ' Only cycle through the locations
        ' that are equal to the old one...
        If tdf.Connect = OldLoc Then
            ' Debug.Print tdf.Name & ":" & tdf.Connect

            Dim whichLoc As String

            If tdf.Name = "T_PAR_2_TBL_1" Or tdf.Name = "T_PAR_2_TBL_2" Then
            ' Only set the tables to partition 2 that were listed as in Partition 2 by the database splitter
                Debug.Print "Setting linked table " & tdf.Name & " FROM " & tdf.Connect & " TO " & partition2Loc
                whichLoc = partition2Loc
            Else
            ' If the name was not listed as in partition 2, set it to partition 1
                Debug.Print "Setting linked table " & tdf.Name & " FROM " & tdf.Connect & " TO " & partition1Loc
                whichLoc = partition1Loc
            End If

            'We will uncomment this when we take the safety off...
            'tdf.Connect = whichLoc
            'tdf.RefreshLink
        End If
    Next tdf
End Sub

1 个答案:

答案 0 :(得分:1)

您可以通过VBA引用TableDefs来更改和更新链接。

 Set db = CurrentDB
 For Each tdf In db.Tabledefs
 If tdf.Connect <> Myconnect Then ''the connect property is a string
    tdf.Connect = MyConnect
    tdf.RefreshLink
 End If

您还可以使用CreateTableDef将外部数据库中的所有表与VBA链接。我一般认为保留一个我想链接的表格并使用它是有用的。

相关问题