Error handling

Im writing a procedure to handle some errors, my project has more than 70 forms, and I have to copy that procedure to On Err event of all those 70 form.
Is there any way that automate this process to avoid adding this procedure to 70 from?
Who is Participating?
YadtrtConnect With a Mentor Author Commented:
I couldnt find what I want in that link, I dont need error handling I need to call a procedure in the On Error Event of all 70 forms
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Lot's of utilities out there that will do this.  One is MZ Tools and it's free:
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
This is a better link:
Takes you right to the download.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

YadtrtAuthor Commented:
I have MZ tool, but I dont how to use it for my situation
You can put something like this in a module:

Public Sub MyErrorHandler(Err As String)
  MsgBox Err, vbCritical, "Error"
End Sub

Then call it from your error handling:

Private Sub Form_Load()
On Error GoTo HandleErr

  Exit Sub
  Call MyErrorHandler("Error# " & Err.Number & ": " & Err.Description)
  Resume ExitHere
End Sub
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<I have MZ tool, but I dont how to use it for my situation>>
  I could have sworn that MZ Tools had the capability to insert it into all modules, but it looks like it only works on a per procedure basis.
 I may have been getting it confused with the VBA Error handler add-in which came with the Access 2000 Office Developer Edition, which does.  But I can't find a download for that.
YadtrtAuthor Commented:
I m calling the procedure, but I should call that procedure in 70 forms. I need something speed up this process instead of opening 70 froms and calling that procedure.
Yep I understand what you are saying now.  Check out this link:
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Sorry, but I cannot find any tool that will do an insert against an entire project or module except for the one included in the A2000 ODE.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Yes ... MZTools will only add an error template (that you have created) per procedure.

Of course, I'm sure you could write code to programatically insert code in every procedure ... but probably not that much fun, and would still require  separate tweaking.  Here is one example of an MZTool error template I created:

    On Error GoTo {PROCEDURE_NAME}_Error



       On Error Resume Next
    'Cleanup here ....
     docmd.Hourglass False
     docmd.SetWarnings True
     On Error GoTo 0

     Call SEH_ErrProcess("Error", "Application execution error.", _
                                  "An unexpected error has occurred.", _
                                  "{MODULE_NAME}", "{PROCEDURE_NAME}", _
                                  Err.Source, Err.Number, Err.Description, Err.LastDllError, _
                                  "If the problem persists, please contact the application developer.")  
    Goto {PROCEDURE_NAME}_Exit


Leigh PurvisDatabase DeveloperCommented:
If you're wanting error handling across the board then you may have to fork out for it depending upon your needs.
Wayne Phillips has done some great, indepth work with the Global Error Handler here.
It far extends the ability of normal error handling, for example Iterating the Call Stack and more.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.