我有一个数据库目录 (*.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