Linking a Table

A linked table appears and behaves just like any other table in your Microsoft Jet database (although there are slight performance differences associated with connecting to and retrieving remote data). All of the information necessary to establish and maintain a connection to the remote data source is stored within the table definition. You can also use the OpenRecordset method in Microsoft Access or Visual Basic for Applications (VBA) to open a linked table. The following example demonstrates how to link an external table, where strDbPath is the path to the database that will contain the linked table:

Dim dbs As Database
Dim tdf As TableDef

Set dbs = OpenDatabase(strDbPath)
' Create new table in Microsoft Jet database.
Set tdf = dbs.CreateTableDef("EmployeeSales")
' Set Connect and SourceTableName properties for table.
With tdf
	.Connect = "FoxPro 3.0;DATABASE=C:\JetBook\Samples\FoxTables\Sales"
	.SourceTableName = "EmpSales"
End With
dbs.TableDefs.Append tdf 

For information about updating link information when tables are moved, see the “Maintaining Links” section later in this chapter.