Access Cookbook - Ken Getz [37]
Figure 2-2. The Form/Report tab of the Options dialog
Discussion
Access normally uses a hidden form named Normal for its form template (and a report of the same name for its report template). If you don't specify your own default properties, all your new forms will use Access's built-in form, report, and control properties. If you create a form named Normal and set the default control and form properties for that form, Access will use that form as a template (that's how the example database has been configured). If you name your form something other than Normal, you can instruct Access to use that form as the template by changing the Form template value in the Tools → Options dialog.
You may want to use different background colors for labels attached to text boxes or combo boxes or for unattached labels, but Access won't let you save specific settings for different types of labels. There is just one type of label, as far as Access is concerned. The default label has one background color, and you must change it as needed depending on its attachment.
To make a report template, follow the same procedure as for a form template (you can omit controls that aren't useful on reports, such as combo boxes and command buttons).
A form or report template only supplies styles (such as color, presence of headers and/or footers, and grid granularity) to new forms; it doesn't supply the controls themselves. If you would like all your forms to contain standard controls at fixed locations, you'll need to make a copy of a standard form and work from that copy. If you copy the entire form, any code attached to the control's event procedures (in the form's module) will also be copied—that's not true if you use templates to create your new forms and reports.
The template form (or report) affects only new objects. If you create a form based on the template and then change the template, any previously created forms based on that template will not be affected.
You can maintain several form or report templates in your database. If you want a specific template for dialog forms and a different one for data-entry forms, keep them both in the database and change the option when you want to create a new form based on a specific template.
See Also
See How Do I Set Control Properties? in the Preface for more basic information on control properties.
2.2. Highlight the Current Field in Data-Entry Forms
Problem
The text cursor is too small in Access, and you can't always tell which text box on a form has the focus. You need some way to really highlight the current field.
Solution
There are many visual cues you can use to tell the user which text box contains the cursor. You can change the color of the text or the background, change the appearance of the text box, or change the appearance of the text box's label.
The simplest solution, which works quite well, is to change the BackColor and SpecialEffect properties of the active control. This solution uses some simple VBA code, which is attached to each control's Enter and Exit events, to do the work. Figure 2-3 shows the sample form, frmEffects, in use (with the City field currently selected).
Figure 2-3. frmEffects in use, showing the active field
Open 02-02.MDB and load frmEffects. As you move from field to field on the form, note that the special effect and the background color of each control change when you enter and again when you leave the control.
Follow these steps to create a form with this same sort of functionality:
Create a new module and name it basSpecialEffects. In the declaration section, create the following constants, which will represent the controls' SpecialEffect and BackColor property settings:
Option Compare Database
Option Explicit
Private Const conWhite = 16777215
Private Const conGray = -12632256
Private Const conIndent = 2
Private