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

Last reviewed: October 24, 1997
Article 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:

   ARTICLE-ID: Q145777
   TITLE     : ACC95: Microsoft Access Sample Reports Available on MSL

   ARTICLE-ID: Q175072
   TITLE     : ACC97: Microsoft Access 97 Sample Reports Available on MSL

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:

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Create a new report based on the Products table.

  3. 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.

  4. 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.
    

  5. Set the CategoryID header section's ForceNewPage property to Before Section.

  6. 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.

  7. Create a line control in the detail section that extends horizontally across the section. Set the line control's Name property to LineControl.

  8. 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 : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.