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

Article translations Article translations
Article ID: 210350 - View products that this article applies to.
This article was previously published under Q210350
This article has been archived. It is offered "as is" and will no longer be updated.
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.
Expand all | Collapse all

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.

  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.
  4. 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.
    					
  5. Set the ForceNewPage property of the CategoryID header section to Before Section.
  6. Add a text box control bound to the ProductName field with the following properties to the detail section of the report:
       Text box
       -------------------------
       Name: ProductName
       ControlSource: [ProductName]
    					
  7. Create a line control in the detail section that extends horizontally across the section. Set the Name property of the line control 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 not to repeat the last value, which creates a constant grid of 15 lines.

Properties

Article ID: 210350 - Last Review: October 25, 2013 - Revision: 4.0
Applies to
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbnosurvey kbarchive kbreport kbhowto kbusage KB210350

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com