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 ...
Get Access™ 2007 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.