Microsoft KB Archive/210350

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

Article ID: 210350

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210350



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

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



For a Microsoft Access 97 version of this article, see 119073.



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 file, RptSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

231851 ACC2000: Microsoft Access 2000 Sample Reports Available in Download Center

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
The following steps demonstrate how to create a report in the sample database Northwind.mdb with a constant number of lines per data group. You can use this method in a main report or subreport:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 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.  Add a text box control with the following properties to the CategoryID header section:   Text box --  Name: TotGrp ControlSource: =Count(*) 'Returns the number of records per group.  Set the ForceNewPage property of the CategoryID header section to Before Section.</li>  Add a text box control bound to the ProductName field with the following properties to the detail section of the report: <pre class="fixed_text">  Text box -  Name: ProductName ControlSource: [ProductName] </li> Create a line control in the detail section that extends horizontally across the section. Set the Name property of the line control 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 not to repeat the last value, which creates a constant grid of 15 lines.

Additional query words: preprinted pre-printed fixed

Keywords: kbhowto kbreport kbusage KB210350

-

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

© Microsoft Corporation. All rights reserved.