ACC2000: How to Print a Constant Number of Lines Per Group
ID: Q210350
|
The information in this article applies to:
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).
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.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals 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 needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the
following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
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: Following the steps in this example will modify the sample
database Northwind.mdb. You may want to back up the Northwind.mdb file
and perform 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.
- 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]
- Create a line control in the detail section that extends horizontally
across the section. Set the Name property of the line control 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 not to repeat the last value,
which creates a constant grid of 15 lines.
Additional query words:
preprinted pre-printed fixed
Keywords : kbusage kbdta RptEvent
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto