Close method

  • Thread starter Thread starter George
  • Start date Start date
G

George

Hi all,

Workspace, Database, Connection, and Recordset (DAO) all
have a Close method. If I don't use this Close method but
directly use Set Object = Nothing to completely destruct
the reference, is there adverse effect?

TIA.
 
There can be an adverse effect if you close something you did not open.

Example:
Dim ws As Workspace
Set ws = dbEngine(0) 'This is already open.
'do something
ws.Close '<=WRONG!!!
Set ws = Nothing

In that case, the workspace variable is pointed at the already-open default
workspace. Closing that attempts to close the open workspace. Although
Access automatically opens it again, your there are side effects - e.g.
"Object no longer set" error when you try to access the RecordsetClone of a
form that was open at the time.

So, if you OpenRecordset, close it.
If you point a recordset variable at something that is already open (such as
the RecordsetClone of a form), do not close it.

Set all objects to Nothing before exiting your code.
 
Back
Top