3 4
Before you start placing controls on a form, you should consider how they will be named. When you drag fields to a form, the controls are given, by default, the same names as the fields to which they are bound. For example, if you drag the LastName field to a form, the text box control that appears on the form is also called LastName. If you click a tool in the Toolbox to place a control on a form, the control appears with a name such as Frame4 (the control type with a number appended).
Problems exist with both types of default names. If a text box has the same name as its field (LastName), you might get a circular reference error (see the Troubleshooting sidebar "The control displays #Error? or #Name when I expect to see the name of the data source or the result of an expression" for more solutions for this type of error). If a control is named Frame4, you have no clue as to what the name represents-for example, when you select a control from the drop-down control selector list on the Formatting toolbar in Design view. To avoid these problems, you might want to use the Leszynski Naming Convention (LNC) control name tags to identify controls, as listed in Table 6-2. The LNC tag is used as a prefix to a base name, which is the field name for bound fields and a descriptive word or phrase for unbound controls. Finding the option group used to select a shipper is much easier if the control is named fraShippers rather than Frame4!
For more details about using the LNC, see Chapter 20, "Customizing Your Database Using VBA Code."
Table 6-2. LNC control tags
Control | Tag |
Bound Object Frame | frb |
Check Box | chk |
Combo Box | cbo |
Command Button | cmd |
Custom | ocx |
Hyperlink | hlk |
Image | img |
Label | lbl |
Line | lin |
List Box | lst |
Option Button | opt |
Option Group | fra |
Page (on a tab control) | pge |
Page Break | brk |
Rectangle (shape) | shp |
Subform/Subreport | sub |
Text Box | txt |
Toggle Button | tgl |
Unbound Object Frame | fru |
Access imposes the following restrictions on control names:
Apart from these restrictions, you can use any combination of numbers, letters and punctuation marks (including spaces). However, I recommend simplifying control names by following these guidelines:
Shorter names allow easier selection of a control in the drop-down control selector list on the Formatting toolbar, which isn't very wide (see Figure 6-6). Avoiding punctuation marks prevents possible problems when you're working with control names in VBA code.
Figure 6-6. Keeping control names short makes it easier to select the appropriate control in the control selector list.
Troubleshooting - The control displays #Error? or #Name when I expect to see the name of the data source or the result of an expression
There are several possible causes for these errors:
Solution: If this is the case, simply reselect a field from the record source, using the field list.
Solution: Fix any errors in the expression, using the Expression Builder to make sure the syntax is correct.
Figure 6-7. This control has the same name as its Control Source field, which could lead to confusion during development.
Solution: The easiest solution is to rename the control with the appropriate tag (for example, txtSales) so that a reference to the field name can't be confused with the control name.
The quickest way to prevent circular reference errors with control names is to run my LNC Renaming COM add-in (described in Chapter 15, "Using Add-Ins to Expand Access Functionality") to rename all controls on a form according to the LNC. Whether you use the LNC Renaming COM add-in to do the renaming or rename the controls on a form manually, using the control tags listed earlier in Table 6-2 will give you the benefits of a naming convention when working with controls.