Part IV: Professional Database Development
1074
Use the MacroError object as a debugging tool or to display messages to the user, who can then
relay that information to you. You can even write these properties to a table to track the errors that
occur in your macros. Use this object within an If action to customize what actions execute based
on the error that occurs. When used in combination with the OnError action, it gives you addi-
tional functionality by handling errors, displaying useful messages, and providing information to
you and the user.
Debugging macros
Trying to figure out what’s going on in a macro can be difficult. The OnError action and
MacroError object make debugging Access macros easier than in previous versions. There are
other tools and techniques that are useful when debugging macros. Use the following list as a
guideline for troubleshooting macros.
l (^) Single Step: Click the Single Step button in the macro design ribbon’s Tools group to
turn on Single Step mode. The Macro Single Step dialog box (shown in Figure 30.18) lets
you see the macro name, condition, action name, arguments, and error number of a
macro action before the action executes. From this dialog box, click Step to execute the
action, Stop All Macros to stop the macro from running, or Continue to finish the macro
with Single Step mode turned off.
FIGURE 30.18
Use the Macro Single Step dialog box to step through a macro.
l MessageBox: Use the MessageBox macro action to display values of variables, error
messages, control settings, or whatever else you want to see while the macro is running.
To see the value of a combo box on a form, set the Message argument as follows:
[Forms]![frmReportMenuEnhanced]![cboReport]
l StopMacro: Use the StopMacro action to stop the macro from executing. Insert this
action at any point in the macro to stop it at that point. Use this in conjunction with the
debug window to check values.