VBA Error Handling PT1

In this VBA Error Handling set (1 & 2) we’ll talk about:

Trapping run-time errors
Creating error handlers
Using the error object

There are 3 main types of VBA Errors:

1. Syntax Errors
2. Logic Errors
3. Run-Time Errors

Syntax errors result when the logic is misspelled, or a wrong keyword is used. The VBA compiler doesn’t know what you are referring to so an error results.

Logic Errors happen when the code is constucted poorly, so it does not perform correctly.

Run Time Errors result when an operation called upon is impossible to carry out, or, when a referenced object in the code does not exist.

The impact of these run time errors can be minimized by error-handling routines.

Some common types of run-time errors are:

-Overflow errors
-Division by zero errors
-Type mismatch errors
-Invalid use of the null character

When a run time error does occur, you can:

-Exit the application
-View the Debug window, at the line the caused the error, because the error line is highlighted, and you can get a clue about what caused the error.
-Go directly to the line that caused the error and try the line again.
-Skip past the error to resume execution of the procedure.
-Get Help on the error (press the F1 keyboard key)

You have to trap these run time errors, or else unexpected results will occur and a cryptic, default error box will result for the user.

Watch the video:

1

‘*************************************
’2. EXITING AN ERROR-HANDLING ROUTINE:
‘*************************************

Here is a chart referencing the “Resume” command’s properties for you to reference:

Statement Description
Resume Resumes execution at the statement that caused the error, and the statement is run again.
Resume Next Execution is resumed at the line after that which caused the error.
Resume (line) (ex. Resume 11) Code execution is resumed at the line specified in the procedure containing the error handler, in the “line” argument.
Resume (label) (ex. Resume ExitHere) Code execution is resumed at the line specified in the procedure containing the error handler, in the “label” argument.

…CODE EXAMPLE

1

<< VBA Debug Part 2 | VBA Error Handling PT2 >>


Get all the videos in this Access VBA collection 100% FREE by signing up at http://vbahowto.com/ms-access-tutorial

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Helpful? Consider giving us a tip. Thanks!

($5 suggested amount)
(...10% of your gift amount will go to charity)




Want All The Access Videos?, Click Here!





Need help? Click and Call LoeblCom Services



Leave a Reply

You must be logged in to post a comment.