Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
ACC2000: How to Use the OpenDatabase Method to Open Third-Party Database Files
Article ID: 210259 - View products that this article applies to.
This article was previously published under Q210259
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies only to a Microsoft Access database (.mdb).
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 Open Database Connectivity (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.
The Connect Property topic in Help 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.
Collapse this tableExpand this table
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 Paradox file named Employee.db located in the C:\ParadoxNwind folder, use the following syntax
Set db = OpenDatabase("C:\ParadoxNwind", True, False, "Paradox 5.x;")instead of:
Set db = OpenDatabase("C:\ParadoxNwind\EMPLOYEE.DB", True, False, "Paradox 5.x;")The first example (without the file name) is the correct one to use. It sets the C:\ParadoxNwind 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.
ExampleTo use the OpenDatabase method to open a Paradox 5.x database, follow these steps:
NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.
For more information about the Connect Property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type connect property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For more information about the OpenDatabase Method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type opendatabase method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.