OpenCurrentDatabase Method

OpenCurrentDatabase Method

See Also         Example         Applies To

You can use the OpenCurrentDatabase method to open an existing Microsoft Access database (.mdb) as the current database. You can use this method to open a database from another application that is controlling Microsoft Access through Automation, formerly called OLE Automation. For example, you can use the OpenCurrentDatabase method from Microsoft Excel to open the Northwind.mdb sample database in the Microsoft Access window.

Note   Use the OpenAccessProject method to open an existing Microsoft Access project (.adp) as the current database.

Syntax

application.OpenCurrentDatabase dbname[, exclusive]

The OpenCurrentDatabase method has the following arguments.

Argument Description
application The Application object.
dbname A string expression that is the name of an existing database file, including the path name and the file name extension. If your network supports it, you can also specify a network path in the following form:

\\Server\Share\Folder\Filename

  Note   If you don't supply the filename extension, .mdb is appended to the filename.
exclusive Optional. A Boolean value that specifies whether you want to open the database in exclusive mode. The default value is False, which specifies that the database should be opened in shared mode.

Remarks

The OpenCurrentDatabase method enables you to open a Microsoft Access database from another application through Automation. Once you have created an instance of Microsoft Access from another application, you must also create a new database or specify a particular database to open. This database opens in the Microsoft Access window.

If you have already opened a database and wish to open another database in the Microsoft Access window, you can use the CloseCurrentDatabase method to close the first database before opening another.

Set the exclusive argument to True to open the database in exclusive mode. If you omit this argument, the database will open in shared mode.

Note   Don't confuse the OpenCurrentDatabase method with the ActiveX Data Objects (ADO) Open method or the Data Access Object (DAO) OpenDatabase method. The OpenCurrentDatabase method opens a database in the Microsoft Access window. The ADO Open method returns a Connection object variable, the DAO OpenDatabase method returns a Database object variable, both of which represent a particular database, but don't actually open that database in the Microsoft Access window.