10.4. When Not to Use VBA

There are times when you will attempt to solve a problem with VBA, only to find out that VBA is not the answer. The following example is such a case. Over time, you will learn to identify what can be solved with code, with a query or multiple queries, and also via the use of controls on a form.

10.4.1. Syncronized Subforms

Subforms are one of the more convenient features of Access. When one form (a subform) is nested inside another form (a main form), Access can keep the subform's data synchronized with the main form by using a common field to relate the two. In a typical example, the main form might be based on a Customers table and a subform could be based on an Orders table. As records are scrolled in the main form, Access filters the subform so that only relevant orders are displayed for that particular customer.

A subform can also be synchronized with another subform. This technique is demonstrated in the Customer Orders form of the Northwind.mdb sample file and illustrated in Figure 10-7.

The first subform is based on order data and is linked to the main form by CustomerID. The second subform contains order details data and is linked to the first subform by the OrderID field. The mechanism Access uses to synchronize a subform relies on the Link Child Fields and Link Master Fields properties of the subform control. Although a wizard can be used to set up a nested subform that is linked to its parent form, subforms that link to another subform must ...

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.