Tricks of the Microsoft Office Gurus

Although it's nice to think that every macro you write will run correctly the first time you code it, the reality is that sometimes it won't. Usually you'll build a simple macro, test it, get it working, and then add more complex statements and so on until you get the final version. One way you'll know that your macro isn't working is when you see the Action Failed dialog box, shown in Figure 13.18. It shows you which macro has failed, what step it was on when it failed, and the arguments that were being used for that step.

Figure 13.18. The Action Failed dialog box appears when Access encounters a problem running your macro.

If you get the Action Failed dialog box, you'll want to jot down the macro name and the step as well as any open forms, reports, or queries. Then click the Halt button to close the dialog box. If you don't already have the macro sheet open for the offending macro, open it and see if you can figure out why that step caused the particular failure. Things to look at are whether what you thought should happen matched what appeared to be happening (particularly a problem with reports), whether the logic in the conditions matches what you thought you coded, and whether there was a condition in the data being analyzed that you didn't expect.

After you've looked at these items, if there still is no apparent problem, it's time to try "stepping" through the macro one action at a time. To do this, begin by opening the macro and any forms or reports that would normally be open when it runs. Select Run, Single Step, or click the Single Step toolbar button to activate the Single Step feature. Then run the macro. As the macro goes through each step, you get a dialog box (similar to the one shown in Figure 13.19) that shows the step being executed. The information about that step is displayed in the dialog box.

Figure 13.19. Use the Macro Single Step dialog box to step through your macro one action at a time.

You have three choices at each step: You can click Step (which is the default) to go to the next action, click Halt to stop execution of the macro, or click Continue to run the macro from that point on without stopping until the end of the macro or until an error is encountered.

Категории