A Connection to the Current Database
The connection allows you to create a connection to either the database you are working on or another database that may be currently closed. You must know the path to the database you want to access. In some cases, you may simply want to connect to the current database. To support this, the CurrentProject property of the Application object is equipped with a property named Connection. This gives you a convenient access to the connection of the currently opened database. Here is an example of invoking it:
Private Sub cmdCurrentConnection_Click()
Dim conCurrent As ADODB.Connection
Set conCurrent = Application.CurrentProject.Connection
End Sub
Remember that, after using a connection, you should release the resources it was using:
Private Sub cmdCurrentConnection_Click()
Dim conCurrent As ADODB.Connection
Set conCurrent = Application.CurrentProject.Connection
Set conCurrent = Nothing
End Sub
When this code executes, it identifies the connection to the current database and stores it in a declared variable named conCurrent.
Partager