OpenDatabase method differences

tomasm

Member
Local time
Yesterday, 23:17
Joined
Nov 20, 2017
Messages
32
What is the difference between the three Set lines below?

Code:
Dim db As DAO.Database

Set db = OpenDatabase("C:\Northwind.accdb")
Set db = DBEngine(0).OpenDatabase("C:\Northwind.accdb")
Set db = DBEngine.WorkSpaces(0).OpenDatabase("C:\Northwind.accdb")

And should either/both of these lines be at the end of a routine that uses the OpenDatabase method?

Code:
Set db = nothing

db.close
 
no difference, just different flavor and all points to Currentdb.
use Codedb, that one is different.
 
There are arguments to be made for using

Code:
db.close
set db = nothing

in that order IF it is your plan to continue by opening another DB after you close this one.

As to the three ways you showed to open the DB, they are the same because of defaults. The default reference is to DBEngine(0) and to Workspaces(0), so when you omit the explicit references, they are still there implied as defaults.
 

Users who are viewing this thread

Back
Top Bottom