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

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

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