msgbartop
Just another WordPress site
msgbarbottom

28 Jan 09 VBA Error Handling with line numbers

Sometimes it is easier to find an error if we know the code line where the error occurred. I have a method to show this in an error message.This is a light version of my error handler and focuses only to the line number of the error.There is a variable called “erl” which contains the line number of the error, so we can use it in the error message:

MsgBox Err.Number & " - " & Erl & " - " Err.Description

But this will show 0 instead of the line number if we didn’t put numbers at the beginning of the rows.Dick Kusleika wrote about the MZ Tools, and MZTools is a great tool for this too.There is an “add line number” icon on the toolbar which made the line numbering in my stead.

addlinenr VBA Error Handling with line numbers

Add Line Number Icon

Voila, it is done, and we can use it.

Reader's Comments

  1. |

    Excellent tip, a useful too for error handling.

  2. |

    Thanks Queries, I will write more about it.

  3. |

    Whether you’re writing Microsoft Access or Visual Basic applications, a comprehensive error handling architecture is critical to a professional solution. Error handling in your VB6/VBA code lets you trap unexpected errors and gracefully exit your application without causing an end user to suffer an unhandled crash on their own.

Leave a Comment

You must be logged in to post a comment.