|[ Team LiB ]|
Recipe 2.1 Make Custom Templates for Forms and Reports
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.
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:
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.
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
|[ Team LiB ]|