O'Reilly logo

Beginning Access™ 2007 VBA by Denise Gosnell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.7. Error Debugging

Now that I have covered several basic ways to write VBA code and to control the flow of the program, let's look at the types of errors you may encounter, how to debug them, and how to write error handlers to handle them.

2.7.1. Types of Errors

The types of errors include: syntax errors, compile errors, runtime errors, and logic errors, each of which will be discussed in turn.

2.7.1.1. Syntax Errors

Syntax errors are errors that occur because the code you wrote does not comply with the required syntax. Figure 2-30 illustrates a syntax error that occurred because the As part of the Dim statement is missing.

2.7.1.2. Compile Errors

Compile errors are errors discovered on compilation that may have a correct code syntax, but for some reason will not compile. Figure 2-31 illustrates a compiler error that has occurred because a CalculateTax function cannot be located. In this particular example, the reason for the compile error is that the function is incorrectly listed as CalculateTax instead of CalculateSalesTax.

2.7.1.3. Runtime Errors

Runtime errors occur at runtime when the code executes. Runtime errors can include errors that occur because of something that it not allowed or supposed to happen. For example, a line of code that tries to assign a variable of one data type to an incompatible value could result in a runtime error. The example in Figure 2-32 runs the CalculateSalesTax function and passes string values as parameters, instead of the required currency ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required