Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Univeral On Error Handler

Status
Not open for further replies.

OrWolf

MIS
Mar 19, 2001
291
Is it possible to have an 'On Error Goto' statement that will cover all the subs in form, rather than entering it in each sub? I have a general error function that I want to call anytime an error occurs in the database, but it's going to take a lot of time and space to put the statements into each sub in each form of the database. See sample below.

Any assistance that you can provide is welcome. Thanks!


Sample:

Option Compare Database
Option Explicit

Private Sub ArchiveLocBtn_Click()

On Error GoTo ErrorHandler

Step = "AdminMenu/ArchiveLocBtn_Click"
DoCmd.Close acForm, "AdminMenu"
DoCmd.OpenForm "ArchiveLocation"

ErrorHandler:
Call GeneralError

End Sub

Private Sub FollowUpDaysBtn_Click()

On Error GoTo ErrorHandler

Step = "AdminMenu/FollowUpDaysBtn_Click"
DoCmd.Close acForm, "AdminMenu"
DoCmd.OpenForm "Criteria_DaysFromFollowUp"

ErrorHandler:
Call GeneralError

End Sub
 
Hi OrWolf,
A Global error handler is a real time saver. 1 form? try 1 database!...I am not promoting, rather, highly recommending to anyone who would like to see some fine examples with a CD to boot, Access 97 Developers Handbook (by now there must be a 2000 version) From Sybex and probably available anywhere, the details described within are superb and the time savings on this issue alone would cover its cost. Five stars+ and I really wish I could show you examples but I must respect the authors rights. :) Gord
ghubbell@total.net
 
There is, indeed, an Access 2000 Developer's Handbook; in fact, it's in 2 volumes. And I join Gord in recommending it highly!

Let me warn you about the hazards of your design, in case you're not aware of them. The example you give calls the generic error routine. When the generic error routine returns, the Err object will have been reset (this happens on every End Sub or Exit Sub). That means that your generic error routine must correct every possible error, because when it returns there is no longer any information about the error that occurred, and no meaningful way to propagate it up the call chain. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top