Is Nothing

I’m working on some largish updates to the Auto FE Updater and I wanted to ensure that the new routine which logs errors would properly handle the situation if there were errors in the error logging routine.  A great deal of searching a dimly remembered discussion brought me to fellow Access MVP Dirk GoldGar’s posting on this topic.  How to know when a Connection or Recordset is open in Programming

If Not rs Is Nothing Then
    rs.Close: Set rs = Nothing
End If
If Not gblLogdb Is Nothing Then _
    gblLogdb.Close
MsgBox "The following error occurred in procedure Log_NewSession of Module Log" & vbCrLf & vbCrLf & _
    Err.Description & vbCrLf & vbCrLf & Command()

Note that the standard error handling routine, including the sub/function name and module name is created by MZTools.  An excellent free utility which I use all the time.

I was rather startled.  This isn’t even documented in Access 97 help.   Allen Browne has a page on this general topic - Nothing? Empty? Missing? Null?

Published Mon, Oct 5 2009 5:09 by Tony
Filed under: , ,

Comments

# re: Is Nothing

I'm confused, Tony. Don't you have:

<pre>  If Not rs Is Nothing Then

   rs.Close

   Set rs = Nothing

 End If

 If Not db Is Nothing Then

   ' if it's not DBEngine(0)(0)

   db.Close

   Set db = Nothing

 End If</pre>

...as part of the exit routine in every sub/function where you open recordsets and db's? Is that what you're saying? This has been standard cleanup code forever.

It doesn't belong in the error handler, though, but in the exit routine, which you resume after you've handled the error.

Keep in mind, though, that it's possible with database variables where you've opened a database other than DBEngine(0)(0) for the variable to be Not Nothing but still closed, so you have to trap for error 3420 and deal with it (how depends on the context). My dbLocal() function for caching a reference to CurrentDB() has included checks for that for quite some time, since I discovered the problem in regular use (you can Google my name and "dbLocal" and you'll find the code, though I can't guarantee it will be the latest version).

--

David W. Fenton

http://dfenton.com/DFA/

Monday, October 05, 2009 11:21 PM by David W. Fenton

Leave a Comment

(required) 
(required) 
(optional)
(required)