
Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
I have the end function as a generic finish to many other subs; in some of
which I turn off SetWarning, change the cursor, etc. In these subs, I use a
construct like:
On Error GoTo ErrX
...other code...
ErrX: Call EndFunction
That way I only need one function to handle most errors and reset the
application stuff. For the most part these subs are not connected to forms
other than to be fired by a button or something.
By the time the code gets to ErrorFunction an error has already occurred, so
I need the code to end; by the time it gets to EndFunction, whatever I was
doing is already done, or an untrapped error has occurred; so I need it to
quit.
I have coded a LOT in Excel and I use this as a standard construct and it
works really well; I don't have to build a separate handler for every sub;
everything is funelled through ErrorFunction and EndFunction - all errors are
automatically handled and cleared and all application settings are reset in
one place: end of story.
Perhaps it won't work in Access, but it seems to be so far. In any case,
shouldn't Err.Clear clear the error? or Is there some other method I'm
missing?
> First, get rid of the End statements in your function: I don't know why
> they're even in the VBA language!
[quoted text clipped - 96 lines]
> >> >
> >> > Thanks again.
Douglas J. Steele - 13 Nov 2006 22:30 GMT
I don't believe there's anyway to clear the DBEngine.Errors collection.
From the Help file:
"Any operation involving DAO objects can generate one or more errors. As
each error occurs, one or more Error objects are placed in the Errors
collection of the DBEngine object. When another DAO operation generates an
error, the Errors collection is cleared, and the new set of Error objects is
placed in the Errors collection. The highest-numbered object in the Errors
collection (DBEngine.Errors.Count - 1) corresponds to the error reported by
the Microsoft Visual Basic for Applications (VBA) Err object."
What that implies is that a) you don't need to loop through the Errors
collection AND include the Err object, as well as b) you should only loop
through the Errors collection if Err.Number is non-zero.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
>I have the end function as a generic finish to many other subs; in some of
> which I turn off SetWarning, change the cursor, etc. In these subs, I use
[quoted text clipped - 138 lines]
>> >> >
>> >> > Thanks again.
Douglas J. Steele - 13 Nov 2006 22:31 GMT
PS.
The normal approach is to have
On Error GoTo ErrorHandler
at the start of each module, and to have ErrorHandler call your generic
error handling routine.
The free MZ-Tools http://www.mztools.com can be used to insert the necessary
code automatically for you.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
>I have the end function as a generic finish to many other subs; in some of
> which I turn off SetWarning, change the cursor, etc. In these subs, I use
[quoted text clipped - 138 lines]
>> >> >
>> >> > Thanks again.