Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link unknown tables

Status
Not open for further replies.

MoLaker

Programmer
Apr 30, 2004
521
US
As a result of another thread, I had this idea. I'm not even sure how one might apply it, but thought I'd post it for you to decide.

This sub accepts the path and name of an Access database as a parameter and links the tables in the external database without having to specifically name the tables.

Code:
Public Sub LinkIt(strDB As String)
' links tables from another db
' sub parameter is string format of path & name of DB
Dim db As Database, strTable As String
Dim i As Integer
    Set db = DBEngine.Workspaces(0).OpenDatabase(strDB)
    db.TableDefs.Refresh
    For i = 0 To db.TableDefs.Count - 1
        strTable = db.TableDefs(i).Name
        ' skip linking of system tables
        If Left(strTable, 4) <> "msys" Then
            DoCmd.TransferDatabase acLink, "Microsoft Access", strDB, acTable, strTable, strTable
        End If
    Next i
    Set db = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top