ACC: How to Print a Constant Number of Lines Per Group
ID: Q119073
 
  | 
The information in this article applies to:
- 
Microsoft Access versions  1.0, 1.1, 2.0, 7.0, 97
 
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
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:
Q145777
 ACC95: Microsoft Access Sample Reports Available in Download Center
Q175072
 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.
 
- Create a line control in the detail section that extends horizontally
   across the section. Set the line control's Name property to LineControl.
 
- 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 
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          : kbusage RptEvent 
Version           : WINDOWS:1.0,1.1,2.0,7.0,97
Platform          : WINDOWS 
Issue type        : kbhowto