Access™ 2007 VBA Programmer's Reference
by Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein
11.3. Working with VBA in Reports
This is a book about VBA, so let's talk about code. More specifically, you'll explore some examples that use specific events and properties such as CanGrow and CanShrink, and then move into some of the more common types of reports that you can create with just a little VBA. Let's start with some of the basics.
To add a module to a report, simply add an event handler for an event such as Open, or set the HasModule property of the report to Yes.
11.3.1. Control Naming Issues
As you add controls, or even when you name fields, there are a few things to keep in mind that make the process of creating queries, forms, and reports much easier. The first is to avoid the use of spaces or punctuation in field and control names. Spaces may make your field names easier to read, but they are not user-friendly when it comes to queries or code. Consider a field named Last Name with a space in the middle. This field name must be bracketed when used in a query. Without the space, brackets are not required. It turns out that brackets are also required when you refer to the field in code, so instead of referring to the field like this:
Me!LastName
you must refer to it like this:
Me![Last Name]
As you can see, using the space in the name makes it harder to read and write in code. Instead, don't use spaces in names; use the Caption property of a field or label control to change the displayed text.
Another issue that causes problems is circular references. A circular ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access