Using CurrentDB()
Microsoft offers a shortcut you can use when creating an object variable that points to the current database. Using the CurrentDB() function, you do not need to first point at the workspace; nor do you need to issue the OpenDatabase method. Instead, you set the Database object variable equal to the result from the CurrentDB() function, as shown in Listing 14.48.
Listing 14.48 Printing the Version of the Database Object
Sub UseCurrentDBFunc()
Dim db As dao.Database
'Point the Database object at a reference to the current
'database
Set db = CurrentDb()
'Print the version property of the database
Debug.Print db.Version
End Sub
This code sets the Database object variable so that it points at the current database object. You cannot use the CurrentDB() function to refer to objects that are not part of the current database. As with all VBA functions that do not require arguments, the parentheses after CurrentDB are optional.