ACC: How to Use OpenDatabase to Open 3rd Party Database FilesLast reviewed: August 29, 1997Article ID: Q132018 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. The OpenDatabase method in Visual Basic for Applications enables you to open an external database file and to work with data access objects (DAO) in that database. The OpenDatabase method supports Microsoft Access databases and a number of third-party databases including any database that supports ODBC. The OpenDatabase method supports opening third-party databases in their native file formats in much the same way that you can link (attach) a table in Microsoft Access. This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.
MORE INFORMATIONThe "Connect Property" topic in Help (or the "OpenDatabase Method (Data Access)" in Microsoft Access version 2.0) states that you use the following settings to connect to the supported database formats.
NOTE: The following table is an excerpt from Help. Please see the Help topic above in your version of Microsoft Access for a full list. Database Type Specifier Example ------------------------------------------------------ dBASE IV dBASE IV; drive:\path dBASE 5 dBASE 5.0; drive:\path Paradox 5.x Paradox 5.x; drive:\path FoxPro 2.5 FoxPro 2.5; drive:\path FoxPro 2.6 FoxPro 2.6; drive:\path Text Text; drive:\path ODBC ODBC; None DATABASE=defaultdatabase; UID=user; PWD=password; DSN=datasourcename [LOGINTIMEOUT=seconds]The Example column lists the drive and the path, but not the file name. A file name is not required for these database formats because the folder (directory) in which the files are stored is considered to be the database. If you do list a file name, you may receive unexpected results. For example, to open a Microsoft FoxPro file named Employee.dbf located in the C:\Foxnwind folder, use the following syntax NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code.
Set db = OpenDatabase("C:\FOXNWIND", True, False, _ "FoxPro 2.5;")instead of:
Set db = OpenDatabase("C:\FOXNWIND\EMPLOYEE.DBF", True, False, _ "FoxPro 2.5;")The first example (without the file name) is the correct one to use. It sets the C:\Foxnwind folder as a database and sets the db variable to a valid Database object. The DBF files contained in the directory are considered in the database's TableDef objects. Be aware that the second example (with the file name) is successful if you use it. The OpenDatabase method opens a database and returns a valid value without returning any errors or warnings. You can even use the database; however, the database has no TableDefs collection. To use the OpenDatabase method to open a FoxPro 2.5 database, follow these steps:
Keywords : kb3rdparty kbprg PgmHowTo Version : 2.0 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |