Recipe 2.1 Make Custom Templates for Forms and Reports

2.1.1 Problem

When you make a new blank form, the form properties and the properties of any control placed on it use the Access defaults. You've decided upon a standard look for your forms and reports that is significantly different from these defaults, and you spend too much time changing control properties on every new form you create to make them match your look. You'd like some way to change the standard default values.

2.1.2 Solution

Access allows you to specify a particular form or report to use as a template for new forms or reports that you create. This solution lists the steps you'll need to take to create your own template for form design. The technique is the same for form templates and report templates.

To see the advantages of using a template to define a new form's settings, load 02-01.MDB and create a new form. Add controls of various types to the form. Notice that some of them look different from the normal Access defaults. To see where the properties are coming from, load the form named Normal from 02-01.MDB in design mode. Each of the controls on this form will act as a template for any new controls on any forms you create in this database. In addition, any new form you create will inherit its own properties from this template form.

To create your own template form, follow these steps:

  1. Create a new blank form.

  2. Make any general changes you want in the form properties, such as changing the GridX and GridY properties to different settings?many users may prefer 24 24, the smallest grid that will show dots. To do this, first display the properties sheet: click on the gray in the upper-left corner of the form or select the Edit Select Form menu item. If you don't want a record selector, navigation buttons, minimize or maximize buttons, a control box, and/or scrollbars on your form template, turn them off in the layout section of the form's properties sheet. In addition, you can choose to center the form automatically when it is opened by changing the AutoCenter property to Yes.

  3. You may also wish to change the form's background color by changing the background color for the form's detail section (click on the detail section bar in form design to select the section). If you want your forms to have page headers/footers or form headers/footers, activate them by checking Format Page Header/Footer or Form Header/Footer and set their colors as well.

  4. Once you have finished setting up the form's general properties, repeat the process to change the default settings for each control you want to modify. There are two ways you can do this:

    • Click on the tool for that control in the toolbox and change the properties in the control's properties sheet. Note that when you do this, the properties sheet's titlebar says Default Label (or whatever control you have selected), as shown in Figure 2-1.

    • Change the controls directly on your form. Add to your form each control type you want to change, and set the properties visibly. Once you're done, select the Format Set Control Defaults menu item, with all the controls selected.

Figure 2-1. The Default Label properties sheet
figs/acb2_0201.gif
  1. Save your form with any name you like.

  2. Finally, open the Tools Options Forms/Reports dialog, as shown in Figure 2-2. (The dialog box may appear differently in your version of Access.) Enter your form's name in the Form Template text box.

Figure 2-2. The Form/Report tab of the Options dialog
figs/acb2_0202.gif

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

2.1.4 See Also

See How Do I Set Control Properties? in the Preface for more basic information on control properties.