"Trevor Best" <no****@besty.org.uk> wrote in message
news:42**********************@news.zen.co.uk...
Tom wrote: "If Not RstSurveySection Is Nothing Then"
worked fine!
You still need to error trap, consider this
Set RstSurveySection = db.openrecordset....
...some code
RstSurveySection.close
... some code
if not RstSurveySection is nothing then
RstSurveySection.close ' <<<< Error will occur here
set RstSurveySection=nothing
end if
RstSurveySection can be closed or become invalid even if you don't
explicitly close it yourself, VBA isn't perfect or invunerable to cosmic
rays :-)
--
[OO=00=OO]
Indeed, so you might have it as part of your 'exit block' like:
Exit_MySub:
On Error Resume Next
If Not RstSurveySection Is Nothing Then
RstSurveySection.Close
Set RstSurveySection = Nothing
End If
Exit Sub
However, if you have the above error handling, it is doubtful whether it is
even worth checking if the object is nothing or not. In other words, you
might as well have:
Exit_MySub:
On Error Resume Next
RstSurveySection.Close
Set RstSurveySection = Nothing
Exit Sub
Having said that, I tend to write code as in the first example - it just
means that my coding always looks recognisable.