Microsoft Office Tutorials and References
In Depth Information
Fixing Compiler Errors
Fixing Compiler Errors
When you write code, the stuff that you’re writing is referred to as source
code. Before your code executes, VBA compiles your source code to an even
stranger language that the computer executes very rapidly. You never
actually see that compiled code; humans work only with source code. If a
problem in the source code prevents compilation, though, you definitely see an
error message.
Most compiler errors happen immediately. If you type just DoCmd. and
press Enter, you get a compiler error. The DoCmd. statement alone on a line
isn’t enough for VBA to compile the line. You need to follow DoCmd. with
some method that’s specific to the DoCmd object.
Not all compiler errors are caught the moment that you press Enter.
Furthermore, code may be in your database (or project) that’s never been
compiled. When you call the code, it compiles on the spot and then
executes. That extra step slows performance.
To compile all the code in a database (or project), both to check for errors
and to improve performance, follow these steps:
1. If you’re currently in the Microsoft Access window, go to Visual Basic
Editor.
When you’re in the Microsoft Access window, you can press Alt+F11 to
switch quickly to Visual Basic Editor.
2. Choose Debug Compile name (where name is the name of the current
database or project) in Visual Basic Editor.
This command compiles all the code in all standard and class modules.
If any errors lurk anywhere, you see a compile-error message box. The
message provides a brief, general description of the problem, as in the
example shown in Figure 6-1.
Figure 6-1:
A sample
compileerror
message.
Search JabSto ::




Custom Search