Microsoft Access 2010 Bible

(Rick Simeone) #1

Part II: Programming Microsoft Access


526


FIGURE 14.1

The Editor tab of the Options dialog box contains a number of important VBA coding options.


These errors are so easy to detect and correct that Access includes an option to automatically check
for syntactical errors. When you select the Auto Syntax Check option, Access checks each line of
code for syntax errors as you enter it in the code editor. Most of the syntax errors caught by Auto
Syntax Check are the most obvious spelling errors, missing commas, and so on. It will not catch
more subtle errors such as data type mismatch, and, of course, Auto Syntax Check won’t catch log-
ical errors.

If you enable Auto Syntax Check, a message box pops up over your code whenever Access detects
a syntax error in your VBA statements. Regardless of whether you enable Auto Syntax Check,
Access also turns the erroneous statement to red to indicate a problem.

Tip
Most developers find that turning the statement to red is enough of an indication of a problem, and they don’t
want to be interrupted by the message box, so they leave Auto Syntax Check unselected.


Notice the Auto Syntax Check check box in the Code Settings area. This option causes Access to
check your code for syntactical errors line by line as you type it into the code editor window.
Figure 14.2 illustrates automatic syntax checking. In this figure, the MsgBox statement contains an
error. Do you see the error?

Notice the stray comma right after the “sSQL: “ portion of the MsgBox line. No comma is
needed here because these arguments to the MsgBox statement are not separated with commas.
Access detects the stray comma and displays the statement in a red typeface to tell you that there’s
a problem on that line.

Tip
If you don’t like red, you can change the color of syntax error text in the Code Colors area of the Editor Format
tab of the Options dialog box.

Free download pdf