In VB6, a runtime error occurs exactly when the Event function is called without error handling. Therefore, at least all your event handling functions (for example, Form.Open ()) should be surrounded by an error handler (yes, I know that VB6 does not have them), which can be implemented like this (we do this in all our applications for example:
Use this as the first line of the EVERY event handling function (this is a large valid label that sets On On at the end):
¦¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯: On Error GoTo ErrorHandler:
Now use this at the end of all these functions:
¦____________________________________________________________________________________________________________________________________: Exit Sub ErrorHandler: handleError CodeDb, "Form_frm_filter_deletecolum", "cmd_deletecolum_Click", err.Number, err.description, err.Source, err.LastDllError, err.Helpfile, err.HelpContext, Erl: err.Clear
But replace the two lines with the module name and function name. And replace each On Error Goto 0 with On Error Goto ErrorHandler .
Now create a handleError function with the given arguments (in my application, it automatically sends an error report to our bugtracking system) and displays a nice error message.
We even pushed it a bit further by pre-creating a process that adds similar lines to all the others (meaning functions not related to the event, or functions just called by other functions) to remember the line in which the error occurred and accumulate the full trace stack (yes, stacktraces in VB6!). In addition, this process adds line numbers to each line, so they are listed in the Erl part of the error handler.
Our tool is written as some MS Access modules, so I can’t just provide it to you, but you see where you should look for it.