Chapter 4 - Checking and Running Macros

Chapter 4 - Checking and Running Macros

4.1Three Stages to Run a Macro

There are three stages to getting a macro to do what you want it to do:

Regular computer users will not be surprised to learn that things can go wrong at each stage!

Examples of the Different Stages of Error

Here is an example of an error for each stage shown above:

Stage / Example of error / Notes
Syntax-checking / / This line could never make sense (you can not end the command with a comma), so it fails the on-line syntax check and is shown in red.
Compilation / / This command could make sense (you might have written a macro called OpenFridge), but when you compile the program the VB Editor will fail to find this macro and report an error.
Running / / This command makes perfect sense, but when you actually run the command will crash – there is no form called frmMadeUp.

4.2Checking your Macros before Running Them

On-Line Syntax Checking

When you press after typing in any line, the VB editor will immediately check that it understands it:

Turning Off Syntax Checking

Syntax-checking is annoying – you might well want to leave a mistake, and come back to correct it later. To turn off syntax checking:

1)From the menu select:

Tools  Options

2)Choose options as shown and then select .

Compiling your Code

When you compile a project, you check that it makes sense to the VB editor.

One of two things will happen next:

If absolutely nothing happens, all of the macros in all of the modules within your current project make sense to the VB editor (note that this does not necessarily mean that they will do what you want them to do!).

Otherwise, the VB editor will stop at the first error it finds:

4.3Running and Stopping Procedures

Running the Currently Selected Procedure

By far the easiest way to test a procedure is to click in it and then run it:

1)Click anywhere at all within your procedure.

2)Choose to run the procedure: / Tool / Keyboard

Stopping a Procedure which is Running

To halt a procedure which is running:

1)Press + (the key is usually at the top right of your keyboard).

2)Access will show in yellow the command it has reached.

3)When code is paused, click on the tool (or press ) to resume the code, or click on the tool to stop it.

© Copyright 2018 Page 1