Part II: Programming Microsoft Access
532
FIGURE 14.8
Single-variable Dim statements are easier to work with than several variables declared as a single VBA
statement.
Compiling VBA Code
After you create a subprocedure or function and want to make sure that all your syntax is correct,
you should compile your procedures by choosing Debug ➪ Compile Project Name from the VBA code
editor window menu (where Project Name is the name of the project set in the Project dialog box,
accessed from the Tools menu). Figure 14.9 shows the Debug menu opened in the editor window.
The compile action checks your code for errors and also converts the programs to a form that your
computer can understand. If the compile operation is not successful, an error window appears, as
shown in Figure 14.10.
This level of checking is more stringent than the single-line syntax checker. Variables are checked
for proper references and type. Each statement is checked for all proper parameters. All text strings
are checked for proper delimiters ,such as the quotation marks surrounding text string. Figure
14.10 illustrates a typical compile-time error. In this case, the name of a method (GetOption) has
been misspelled, and the compiler is unable to resolve the misspelled reference.
Access compiles all currently uncompiled procedures, not just the one you’re currently viewing. If
you receive a compilation error, immediately modify the code to rectify the problem. Then try to
compile the procedure again. If there are further compile errors, you’ll see the next error.
Note
Unfortunately, the VBA compiler reports compilation errors one at a time. Most other compilers (such as the
compilers in Visual Studio .NET) show you as many errors as they find during compilation.