Part IV: Professional Database Development
1070
FIGURE 30.15
Errors in macros cause the macro to cease operation.
A common error that’s easy to demonstrate is the divide-by-zero error. For the next example,
mcrDivision (shown in Figure 30.16) contains two temporary variables — MyNum and
MyDenom — set with the InputBox() function asking for a numerator and denominator. The
MessageBox action shows the result — [TempVars]![MyNum]/[TempVars]![MyDenom] —
in a message box and the RemoveTempVar actions remove the variables from memory.
FIGURE 30.16
mcrDivision divides the numerator by the denominator and generates an error when the denominator is zero.
Run the macro and enter 1 for the numerator and 2 for the denominator; the macro runs and displays a
message box saying 1 divided by 2 is 0.5. Run the macro again and enter 0 in the denominator; a
divide-by-zero error occurs and the macro stops running. Without error handling, the two
RemoveTempVar actions won’t run and won’t remove the temporary variables from memory.
If an error occurs in another macro — such as a string of action queries — any queries after an
error occurs won’t run. Adding error handling to your macros allows you to choose what to do
when an error occurs while a macro’s running.