Microsoft KB Archive/292050

= ACC2002: Keeping Subreport or Text Box Data Together on a Page =

Article ID: 292050

Article Last Modified on 11/6/2003

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q292050



Novice: Requires knowledge of the user interface on single-user computers.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 208541.



SUMMARY
Subreports and text box controls do not have a KeepTogether property to prevent the controls' data from printing across two or more pages. However, you can simulate the KeepTogether property behavior by creating &quot;artificial&quot; group sections and placing the subreport and text box controls in these sections. Then, you can set the group's KeepTogether property to Yes, which causes Microsoft Access to test the layout of the controls before printing them and to keep the text together on one page.



MORE INFORMATION
The following steps use the sample database Northwind.mdb to demonstrate how you can use report sections to simulate a KeepTogether property for subreport and text box controls.

Creating a Subreport
 Open the sample database Northwind.mdb or the Access project NorthwindCS.adp. Run the Report Wizard to create a report based on the Products table. On the Which Fields do you want on your report? page, add the following fields to the Selected Fields list:

ProductName

QuantityPerUnit

UnitPrice

 Click Finish. Close the report. In the Database window, right-click the Products report, and then click Rename on the menu that appears. Type the following name for the report, and then press ENTER:

srptProducts

</li></ol>

Creating a Main Report
<ol> Run the Report Wizard to create a report that is based on the Categories table.</li> On the Which Fields do you want on your report? page, add all of the fields to the Selected Fields list.</li> Click Finish.</li> Close the report.</li> In the Database window, right-click the Categories report, and then click Rename on the menu that appears. Type the following name for the report, and then press ENTER:

rptCategories

</li> Open the rptCategories report in Design view.</li> On the View menu, click Sorting and Grouping.</li> Under the Field/Expression list, select CategoryID in the first row, and then type the following expression in the second row (below CategoryID):

=1

</li> For the &quot;=1&quot; expression, select &quot;Yes&quot; in the GroupFooter property.</li></ol>

Adding the Subreport to the Main Report
<ol> Drag the srptProducts report from the Database window to the &quot;=1&quot; group footer to create the subreport container.</li> Change the following subreport control properties:

Name: Products

ControlSource: Report.srptProducts

LinkChildFields: CategoryID

LinkMasterFields: CategoryID

CanGrow: Yes

Left: 0

Top: 0

Width: 7

Height: .25

</li> Select the &quot;=1&quot; group footer, and then set its properties as follows:

KeepTogether: Yes

CanGrow: Yes

Height: .25

</li> Preview the rptCategories report. Note that the subreport data is printed on one page, rather than across two or more pages.</li></ol>

Additional Notes

 * Creating an &quot;artificial&quot; group (as demonstrated in this article) works well for subreport controls, as well as for text box controls that are bound to Memo fields. When Memo fields are being printed, there are no events triggered until the Memo field is finished. Therefore, you cannot tell if the Memo field data will be split between two pages. By placing the Memo field in its own &quot;artificial&quot; group, the group's KeepTogether property will test the layout of the Memo field before it is printed and keep the text together on one page when it is printed.
 * If your subreport or text box does not grow, you can size the subreport control in the main report to be the same size as the subreport itself. Then, set the KeepTogether property of the subreport's section on the main report to No. When you print the report, Microsoft Access will not generate a page break in the middle of a control.
 * If your subreport or text box does grow, consider placing the control into its own section and setting the KeepTogether property for the subreport's section in the main report to Yes.

Additional query words: inf

Keywords: kbhowto KB292050

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.