OpenDatabase method differences (1 Viewer)

tomasm

New member
Local time
Today, 10:14
Joined
Nov 20, 2017
Messages
18
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:14
Joined
May 7, 2009
Messages
19,245
no difference, just different flavor and all points to Currentdb.
use Codedb, that one is different.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:14
Joined
Feb 28, 2001
Messages
27,188
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

Top Bottom