VB Code to link tables

Massoud

Registered User.
Local time
Today, 02:39
Joined
Jul 11, 2002
Messages
37
Hi!
I'm looking for vb code that by giving the name and path of an mdb file, links all of the tables defined in it to my database.
(Access97)

Thanks
 
Try this:
Code:
Public Sub linkTables(filePath As String)

    Dim dbs As Database, tbd As TableDef, tbdNew As TableDef

    Set dbs = OpenDatabase(filePath)

    For Each tbd In dbs.TableDefs
        If tbd.Attributes = 0 Then
            Set tbdNew = CurrentDb.CreateTableDef(tbd.Name)
            tbdNew.Connect = "MS Access;DATABASE=" & filePath
            tbdNew.SourceTableName = tbd.Name
            CurrentDb.TableDefs.Append tbdNew
            Set tbdNew = Nothing
        End If
    Next tbd

    dbs.Close
    Set dbs = Nothing

End Sub

For example:
linkTables "C:\MyDatabase.mdb"

...will link all normal tables from C:\MyDatabase.mdb to your current database.
 

Users who are viewing this thread

Back
Top Bottom