O'Reilly logo

Access™ 2007 VBA Programmer's Reference by Armen Stein, Geoffrey Griffith, Rob Cooper, Teresa Hennig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.3. Other VBA Structures

You'll often use a few other VBA components within your code: comments, constants, and to a lesser extent, enums. This section provides a brief introduction to each and shows you how these components can be helpful within your code.

5.3.1. Comments

VBA programming consists of writing statements and comments. Although comments are not explicitly required, they make it much easier to read the code and figure out what it is intended to do. As you've probably noticed, uncommented code is hard to read and difficult to understand. Comments are especially helpful to someone else who may end up working with your code; of course, if it's been a while since you've worked on a particular project, you'll find that those comments can get you back up to speed quickly.

When working with the VBA Editor in Access, you can add comments by prefacing text with an apostrophe. The default setting is that comments appear in green, so they are quickly recognized when scanning through code. Although you can insert comments at the end of a line of code, they are more commonly used before or after a procedure or function. Comments are ignored during code execution. You can have one or many lines of comments in a procedure, and VBA will ignore them all. Comments don't slow down the execution of your code; so you can use them liberally. At a minimum, your comments should list what the procedure is for and when it was written. Figure 5-2 shows a typical procedure with detailed comments—albeit ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required