O'Reilly logo

Access 2003 VBA Programmer's Reference by Armen Stein, Graham Seach, Teresa Hennig, Patricia Cardoza

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

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.

4.3.1. Comments

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 ...

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