Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My solution is the following:</p> <ol> <li>install <a href="http://www.mztools.com" rel="noreferrer">MZ-Tools</a>, a very interesting add-on for VBA. No they did not pay me, anyway it is free.</li> <li>program a standard error handler code such as this one (see MZ tools menu/Options/Error handler):</li> </ol> <hr> <pre><code>On Error GoTo {PROCEDURE_NAME}_Error {PROCEDURE_BODY} On Error GoTo 0 Exit {PROCEDURE_TYPE} {PROCEDURE_NAME}_Error: debug.print "#" &amp; Err.Number, Err.description, "l#" &amp; erl, "{PROCEDURE_NAME}", "{MODULE_NAME}" </code></pre> <hr> <p>This standard error code can be then automatically added to all of your procs and function by clicking on the corresponding button in the MZ-Tools menu. You'll notice that we refer here to an undocumented value/property of VBA (2003 edition), 'erl', which stands for 'error line'. You got it! If you ask MZ-Tools to automatically number your lines of code, 'erl' will then give you the number of the line where the error occured. You will have a complete description of the error in your immediate window, such as:</p> <pre><code>#91, Object variable or With block variable not set, l# 30, addNewField, Utilities </code></pre> <p>Of course, once you realize the interest of the system, you can think of a more sophisticated error handler, that will not only display the data in the debug window but will also:</p> <ol> <li>display it as a message on the screen</li> <li>Automatically insert a line in an error log file with the description of the error <strong>or</strong></li> <li>if you are working with Access or if you are connected to a database, automatically add a record to a Tbl_Error table! </li> </ol> <p>meaning that each error generated at the user level can be stored either in a file or a table, somewhere on the machine or the network. Are we talking about <strong>building an automated error reporting system</strong> working with VBA?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload