Supplying Connection Information for Opening
an External Table
When you open an external table directly, you must supply a database path and a source database type as arguments in the OpenDatabase method. The source database name argument, dbname, is described in detail in the next section, “Specifying Database Names.”
The following code fragment assumes you want to connect to the FoxPro 3.0 database named Sales:
Set dbs = OpenDatabase("C:\JetBook\Samples\FoxTables\Sales", _
False, False, "FoxPro 3.0")
In general, you can use the following methods and properties in VBA code to specify connection information:
-
OpenDatabase method. Use the connect argument of the OpenDatabase method to specify the source database type, and use the dbname argument to specify the database name. For ODBC data sources, use the connect argument of the OpenDatabase method to specify the data source name (DSN).
-
CreateTableDef method. Use the connect argument of the CreateTableDef method to specify the source database type or the database path, and use the sourcetablename argument to specify the source table name.
-
OpenRecordset method. Use the source argument of the OpenRecordset method to specify the source table name.
-
Connect property. Use the Connect property to specify the source database type with the database specifier setting and use the database name with the database path setting. For ODBC data sources, use the Connect property to specify connection information including the DSN, user ID, password, and database name. An ODBC data source connection string uses the same syntax whether you are connecting through an ODBCDirect workspace object or a Microsoft Jet workspace object.
For examples illustrating how to supply connection information for opening an external table, see the “Putting It All Together: Building a Connection String” section later in this chapter.