The information in this article applies to:
- Microsoft Access versions 1.0, 1.1, 2.0
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
This article describes how to create a label that will print at the top of
each report page when a data group spans multiple pages.
The events used in this technique capture the value of the group in the
page footer. If this value is the same as the page header value on the
next page, a label containing "Continued from previous page..." is printed
at the top of the page.
MORE INFORMATION
The steps below use the sample database NWIND.MDB to demonstrate how to
create a label that is printed at the top of each report page when a data
group spans multiple pages:
- Open the sample database NWIND.MDB and create a new module.
- Enter the following global Declarations and functions in the module.
NOTE: In the following sample code, underscores (_) are used as line-
continuation characters. Remove the underscores from the end of the
line when re-creating this code in Access Basic.
'-----------------------------------------------
'Global Declarations
'-----------------------------------------------
Global CurrentGroupVal as String
'-----------------------------------------------
'Code Section
'-----------------------------------------------
Function SetGlobalVar (InReport as Report)
CurrentGroupVal = InReport!SetGroupVal
End Function
Function SetContinuedLabel (InReport as Report)
If InReport.Page <> 1 then
InReport!ContinuedLabel.Visible = _
IIf(Trim(InReport!CheckGroupVal) = _
Trim(CurrentGroupVal), True, False)
End If
End Function
- Open the List Of Products By Category report in Design view.
- Increase the height of the detail section to approximately 1 inch.
- Increase the height of the page header section by about 0.5 inch. Add
a label to the page header section. Position the label below the
existing fields. Set the label's Caption property to "Continued from
previous page..." and set its ControlName property to ContinuedLabel.
Set the label's Visible property to No.
NOTE: In Microsoft Access version 2.0, the ControlName property is
called the Name property.
- From the View menu, choose Field List.
- Add a text box bound to the Category Name field by dragging the
Category Name field to the page header section. Change the text box's
ControlName property to CheckGroupVal, and set its Visible property to
No.
- Click anywhere in the page header section not occupied by a control to
display the page header properties in the property sheet. Set the page
header's OnPrint property as follows:
=SetContinuedLabel(Report)
- Add a text box bound to the Category Name field in the page footer
section. Change the text box's ControlName property to SetGroupVal,
and set its Visible property to No.
- Click anywhere in the page footer section not occupied by a control.
Set the page footer's OnPrint property as follows:
=SetGlobalVar(Report)
- Preview the report. Note the "Continued from previous page..." message
at the top of any page whose category details span more than one page.
Note that these steps are for illustrative purposes only; your report
may require adjustments other than those mentioned. You may want to set
the sections KeepTogether properties to Yes to keep sections from being
split across pages. In the example, you may also want to set the Category
Name header section's ForceNewPage property to Before Section to help
control the page layout.
In Microsoft Access version 2.0, there is a new GroupKeepTogether property
that you can use to keep groups of records together or to keep the group
header with the first record in the group. You may want to experiment with
this property to see how it affects your report's layout.