Microsoft KB Archive/119073

= ACC: How to Print a Constant Number of Lines Per Group =

Article ID: 119073

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q119073



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article describes how to create a constant number of lines per data group on a report. You can use this method to consistently print 15 lines per data group, regardless of the actual number of items within the group. Note that if the group contains more than 15 items, the function used by this method will not apply.

NOTE: This article explains a technique demonstrated in the sample files, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0) and RptSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

145777 ACC95: Microsoft Access Sample Reports Available in Download Center

175072 ACC97: Microsoft Access 97 Sample Reports Available in Download Center



MORE INFORMATION
This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in earlier versions. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in version 2.0.

The steps below demonstrate how to create a report in the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0 or earlier) with a constant number of lines per data group. You can use this method in a main report or subreport:  Start Microsoft Access and open the sample database Northwind.mdb. Create a new report based on the Products table. Group the data by the CategoryID field. Set the GroupHeader property to Yes.

NOTE: In Microsoft Access 2.0 or earlier, there is a space in Category ID. Add a text box control with the following properties to the CategoryID header section:

Name: TotGrp

ControlSource: =Count(*) 'Returns the number of records per group.

 Set the CategoryID header section's ForceNewPage property to Before Section. Add a text box control bound to the ProductName field with the following properties to the report's detail section:

Name: ProductName

ControlSource: [ProductName]

NOTE: In Microsoft Access 2.0 or earlier, there is a space in Product Name.</li> Create a line control in the detail section that extends horizontally across the section. Set the line control's Name property to LineControl.</li>  Create a new module and type the following lines in the Declarations section: Option Compare Database 'Use database order for string comparisons. Option Explicit Global TotCount As Integer

' Call the SetCount function from the group header section's     ' OnPrint property using the syntax: =SetCount(Report)

Function SetCount (R As Report) TotCount = 0 R![ProductName].Visible = True End Function

' Call the PrintLines function from the detail section's OnPrint ' property using the syntax: =PrintLines(Report,[TotGrp]).

Function PrintLines (R As Report, TotGrp) TotCount = TotCount + 1 If TotCount = TotGrp Then R.NextRecord = False ElseIf TotCount > TotGrp And TotCount < 15 Then R.NextRecord = False R![ProductName].Visible = False End If     End Function </li></ol>

This method repeats the last detail line for a data group until the total number of constant lines has been created. In this example, the last detail line is repeated until 15 detail lines have been printed for each group. The ProductName control is hidden in order to not repeat the last value, which creates a constant grid of 15 lines.

Additional query words: preprinted pre-printed fixed

Keywords: kbhowto kbprogramming kbusage KB119073

-

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

© Microsoft Corporation. All rights reserved.