When you link an external table by creating or modifying a TableDef object, you must supply information indicating the type and location of the external database as well as the name of the table you want to link. You can accomplish this by doing one of the following:
The following code fragment sets the connection information with the Connect and SourceTableName properties and assumes you want to connect to the table Q1Sales in a FoxPro 3.0 database named Sales. In this example, strDbPath
is the path to the Microsoft Jet database:
Dim dbs As Database, tdf As TableDef Set dbs = OpenDatabase(strDbPath) ' Create a new TableDef object in a Microsoft Jet database. Set tdf = dbs.CreateTableDef("FirstQuarterSales1996") ' Set the Connect and SourceTableName properties to link the TableDef object. With tdf .Connect = "FoxPro 3.0;DATABASE=C:\JetBook\Samples\FoxTables\Sales" .SourceTableName = "Q1Sales" End With ' Append the linked TableDef object. dbs.TableDefs.Append tdf
Important Use a semicolon (;) to separate arguments specified in the Connect property. Don’t include any spaces on either side of the semicolon.
The following code fragment sets the connection information when you create the TableDef object and assumes you want to connect to the table Q1Sales in a FoxPro 3.0 database named Sales. In this example, dbs
is a Database object and tdf
is a TableDef object. Note that you must include the value of 0 for the attributes argument:
Set tdf = dbs.CreateTableDef("FirstQuarterSales1996", _ 0, "Q1Sales", "FoxPro 3.0;DATABASE=C:\JetBook\Samples\FoxTables\Sales;")
You can also connect to a data source on an HTTP or FTP server. For example, the following code fragment creates a TableDef object linked to an external FoxPro table on an FTP server:
Set tdf = dbs.CreateTableDef("FirstQuarterSales1996", _ 0, "Q1Sales", "FoxPro 3.0;DATABASE=FTP://WebServer/YTDSales/Sales;")