سؤال

I have a directory of databases (*.mdb)s which are linked to several other *.mdb in other locations.

We've split the original database from one file into two partitions. The databases in the directory point to the original database file (and a few other databases as well). Now I need to re-link the tables from each database in the directory to the correct partition of the original (now split) database.

I've been going through manually and re-linking the tables in each database's Linked Table Manager, but this is grossly inefficient, and if I could just query the Linked Table Manager somehow, I could easily find out if I have changed the correct number of tables.

Is there any way to query the Linked Table manager? Through VB or even using the system tables and SQL using table name and file location?

Note I am opening the files in MS Access 2003, but MS Access 2003 is opening them and reporting Access 2000 format.

Per Remou's suggestion here is some code I wrote to relink the tables:

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
هل كانت مفيدة؟

المحلول

You can change and update links by referring to the TableDefs through VBA.

 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

You can also link all tables in an external database with VBA by using CreateTableDef. I generally find it useful to keep a table of tables I want to link and use that.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top