4.3. Other VBA Structures

There are a few other VBA components you'll use often within your code. These are 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.


VBA programming consists of writing statements and comments. While comments are not explicitly required, uncommented code is hard to read and very difficult to understand, especially if someone else needs to work with your code. When working with the VBA Editor in Access, comments are prefaced with an apostrophe and appear in green. 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 don't be afraid to use them liberally. At a minimum, your comments should list what the procedure is for and when it was written. Figure 4.2 shows a typical procedure with detailed comments.

Figure 4.2. Figure 4-2

You might be wondering why you need to add comments to code you're writing for your own applications. Well, any time you write code, there's a chance that code will be used for more than one application. It's also possible that someone else will eventually inherit your code. What if you choose to leave your current position to take a new job? When your company hires ...

Get Access 2003 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.