Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 14: Debugging Your Access Applications


527


FIGURE 14.2

Automatic syntax checking can save you from simple bugs.


Fixing syntactical errors is straightforward: Simply examine the line for misspellings, stray charac-
ters, missing quotation marks, and so on. Very often, syntax errors are introduced by using paren-
theses where they aren’t needed (or omitting them when they’re necessary!), improperly placing
square brackets, and so on.

Tip
Many syntactical errors can be avoided by adhering to the naming conventions frequently mentioned in this
book: Avoid spaces in object names, use mixed-case names to make them easier to read, and so on. Anything
you can do to make your code easier to understand goes a long way toward avoiding silly syntactical errors.


Require Variable Declaration
The Require Variable Declaration setting automatically inserts the Option Explicit directive
into all VBA modules in your Access application. This means, of course, that all variables must be
explicitly declared (with a Dim, Private, Public, or Static keyword) before they’re used. The
Require Variable Declaration option is selected by default and is preferred by most experienced
Access developers.

Caution
Without Option Explicit, variables don’t have to be declared, so it’s easy to fall into a habit of using vari-
ables without carefully considering appropriate data types, naming conventions, or the impact of variable
scope. Code written without the benefit of Option Explicit can get ugly pretty fast.

Free download pdf