Application.CurrentDb Method
| Access Developer Reference |
Syntax
expression.CurrentDb
expression A variable that represents an Application object.
Return Value
Database
Remarks
Note |
|---|
| In Microsoft Access the CurrentDb method establishes a hidden reference to the Microsoft Office 12.0 Access Conectivity Engine object library in a Microsoft Access database. |
In order to manipulate the structure of your database and its data from Visual Basic, you must use Data Access Objects (DAO). The CurrentDb method provides a way to access the current database from Visual Basic code without having to know the name of the database. Once you have a variable that points to the current database, you can also access and manipulate other objects and collections in the DAO hierarchy.
You can use the CurrentDb method to create multiple object variables that refer to the current database. In the following example, the variables dbsA and dbsB both refer to the current database:
| Visual Basic for Applications |
|---|
|
Note |
|---|
| In previous versions of Microsoft Access, you may have used the syntax Visual Basic for Applications Visual Basic for Applications Visual Basic for Applications Visual Basic for Applications |
| Visual Basic for Applications |
|
| Visual Basic for Applications |
|
| Visual Basic for Applications |
|
| Visual Basic for Applications |
|
If you need to work with another database at the same time that the current database is open in the Microsoft Access window, use the OpenDatabase method of a Workspace object. The OpenDatabase method doesn't actually open the second database in the Microsoft Access window; it simply returns a Database variable representing the second database. The following example returns a pointer to the current database and to a database called Contacts.mdb:
| Visual Basic for Applications |
|---|
|
Note