Setting up Default Forms and Report templates

        6 votes: *****     33,95 views      No comments
by Allen Browne, 20 April 2005    (for ALL VERSIONS of Access)

Microsoft Access Tips for Serious Users

Provided by Allen Browne.  Created: November 2003.  Updated: April 2009.


Default forms, reports and databases

Access provides a way to set up a form and a report, and nominate them as the template for new forms and reports:

  • in Access 1 - 2003: Tools | Options | Forms/Reports,
  • in Access 2007: Office Button | Access Options | Object Designers.

That's useful, as it lets you create forms and reports quickly to your own style.

However, these forms/reports do not inherit all properties and code. You will get a better result if you copy and paste your template form or report in the database window (Access 1 - 2003) or Nav Pane (Access 2007.) The form created this way inherits all properties and event procedures.

It will take you 30-45 minutes to set up these default documents. They will save 5-15 minutes on every form or report you create.

A default form

Create a new form. If you normally provide navigation or filtering options in the Form Header section, display these sections (Form Header/Footer on View menu in Access 1 - 2003; on the Layout ribbon, the rightmost icon in the Show/Hide group in Access 2007.) Drag them to the appropriate height. In addition to your visual preferences, consider setting properties such as these:

Allow Design Changes Design View Only Disallow runtime changes. (Access 2003 and earlier.)
Allow PivotTable View No Disallowing these views prevents tinkerers from trying them from the toolbar or View menu.
Allow PivotChart View No
Width 6" Adjust for the minimum screen resolution you anticipate.

Now comes the important part: set the default properties for each type of control.

Select the Textbox icon in the Toolbox (Access 1 - 2003) or on the Controls group of the Design ribbon (Access 2007.) The title of the Properties box reads, "Default Text Box". Set the properties that new text boxes should inherit, such as:

Special Effect Flat Whatever your style is.
Font Name MS Sans Serif Choose a font that will definitely be on your user's system.
Allow AutoCorrect No Generally you want this on for memo fields only.

Repeat the process for the default Combo Box as well. Be sure to turn Auto Correct off - it is completely inappropriate for Access to correct items you are selecting from a list. Set properties such as Font Name for the default Label, Command Button, and other controls.

Add any event procedures you usually want, such as:

  • Form_BeforeUpdate, to validate the record;
  • Form_Error, to trap data errors;
  • Form_Close, to ensure something (such as a Switchboard) is still open.

Save the form. A name that sorts first makes it easy to copy and paste the form to create others.

A default Continuous Form

Copy and paste the form created above. This form will be the one you copy and paste to create continuous forms.

You have already done most of the work, but the additional properties for a continuous form might include:

  • Set the form's Default View property to Continuous Forms.
  • For the default Text Box, set Add Colon to No. This will save removing the colon from each attached label when you cut them from the Detail section and paste them into the Form Header.
  • If your continuous forms are usually subforms, consider adding code to cancel the form's Before Insert event if there is no record in the parent form.

Create other "template forms" as you have need.

A default report

The default report is designed in exactly the same way as the forms above. Create a blank report, and set its properties and the default properties for each control in the Toolbox.

Suggestions:

  1. Set the default margins to 0.7" all round, as this copes with the Unprintable area of most printers:
    • In Access 1 - 2003, choose Page Setup from the File menu, and click the Margins tab.
    • In Access 2007, click the Extend arrow at the very bottom right of the Page Layout group on the Page Setup ribbon.
       
  2. Set the report's Width to 6.85". (Handles Letter and A4 with 1.4" for margins.)
     
  3. Show the Report Header/Footer (View menu in Access 1 - 2003; in Access 2007, the rightmost icon in the Show/Hide group on the Layout ribbon).
     
  4. Add a text box to the Report Header section to automatically print the report's caption as its title. Its Control Source will be:
        =[Report].[Caption]
     
  5. Add a text box to the Page Footer section to show the page count. Use a Control Source of:
        ="Page " & [Page] & " of " & [Pages]
     
  6. Set the On No Data property to:
        =NoData([Report])
     

The last suggestion avoids displaying "#Error" when the report has no data. Copy the function below, and paste into a general module. Using the generic function means you automatically get this protection with each report, yet it remains lightweight (no module) which helps minimize the possibility of corruption. The code is:

Public Function NoData(rpt As Report)
    'Purpose: Called by report's NoData event.
    'Usage: =NoData([Report])
    Dim strCaption As String   'Caption of report.
    
    strCaption = rpt.Caption
    If strCaption = vbNullString Then
        strCaption = rpt.Name
    End If
    
    DoCmd.CancelEvent
    MsgBox "There are no records to include in report """ & _
        strCaption & """.", vbInformation, "No Data..."
End Function

A default database (Access 2007 only)

In Access 2007, you can also create a default database, with the properties, objects, and configuration you want whenever you create a new (blank) database.

  1. Click the Office Button, and click New. Enter this file name:
        C:\Program Files\Microsoft Office\Templates\1033\Access\blank
    and click Create. The name and location of the database are important.
    If you installed Office to a different folder, locate the Templates on your computer.
  2. To set the database properties, click the Office Button and choose Access Options.
    On the Current Database tab of the dialog, uncheck the Name AutoCorrect options to prevent these bugs.
    On the Object Designers tab, uncheck Enable design changes for tables in Datasheet view to prevent users modifying your schema.
    Set other preferences (such as tabbed documents or overlapping windows, and showing the Search box in the Nav Pane.)
  3. After setting the options, set the references you want for your new databases.
    Open the code window (Alt+F11) and choose References on the Tools menu.
  4. Import any objects you always want in a new database, such as:
    • the default form and report above,
    • modules containing your commonly used functions,
    • tables where you store configuration data,
    • your splash screen, or other commonly used forms.
    To import, click the External Data tab on the ribbon, then the Import Access Database icon on the Import group.

Now any new database you create in Access 2007 will have these objects included, properties set, and references selected.

You can create default databases for both the new file format (accdb) and the old format (mdb) by creating both a blank.accdb and a blank.mdb in the Access templates folder.

Conclusion

You will quickly discover these default forms, reports, and databases not only save time, but help provide a consistency in style and functionality throughout your application.


Home Index of tips Top

Rate this article:  Your rating: PoorYour rating: Not so goodYour rating: AverageYour rating: GoodYour rating: Excellent


This is a cached tutorial, reproduced with permission.

Have your say - comment on this article.

What did you think of 'Setting up Default Forms and Report templates'?

No comments yet.

Why not be the first to comment on this article?!

Have your say...

Name
E-mail (e-mail address will be kept private)
Comments


Comments require approval before being displayed on this page (allow 24 hours).