Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count in page header?

Status
Not open for further replies.

mdmarney

IS-IT--Management
Jan 16, 2003
68
US
I have between 1 and three groups to a page on a given report. I would like the header to display a total count from each grouped section. Is this a VB problem or is there a simple expression? *************
M. MARNEY
 
It would be very easy in the Group Footer but the Page Header doesn't have a lot of use when it comes to calculations. If you can use the group footer then it would simply be
=Count([GroupControlName])
This would return a count for each group.

Paul
 
Hi,
I believe that this is entirely possible. Taking Paul's bit of code, we can use that to create your page headers.

1) We need to add a public variable to the General Declarations section of the report that will keep track of the number of groups. This will be:
Public intGroupCount as integer
intGroupCount = 0 'initialize variable
' public variables are available to the entire report...
' and will be destroyed when the report is closed

2) Create 3 text boxes in the page header. These can be called txtGroup1Count, txtGroup2Count, etc. If necessary, add three labels to correspond to these. Set all 3 (or 6) controls visibility to No. The text boxes need to have the format set to Standard, or some other appropriate format for your counts.

3) Add a Group Footer, and a text box with the visible property set to No. We can call it txtGroupCounter, and contains the code from PaulBricker (except that you will count something from the detail line). This code will go into the Control Source property:
= Count([fldInDetailLineThatIsToBeCounted])

4) As PaulBricker indicated, you can have a GroupFooter, but it doesn't have to contain anything other than your non-visible text box (which now contains a counter for each group) and your code statements. So, in the OnFormat event for this footer, add this:
'increment intGroupCount by 1
intGroupCount = intGroupCount + 1
' only supposed to be a max of 3 groups on page
if intGroupCount > 3 Then
msgBox "Too many groups on page, contact M. Marney"
end if
' The following code could be converted to Select Case
' Set the visible properties of both the label
' and the text box for each counter ONLY when
' appropriate (e.g., if only 1 group, then only
' display txtGroup1Count and lblGroup1Count)
if intGroupCount = 1 Then
txtGroup1Count.visible = True 'make text box visible
lblGroup1Count.visible = True 'make label visible
txtGroup1Count = txtGroupCounter
end if
'repeat code blocks for intGroupCount = 2, =3

5) The page footer needs to have some code to reinitialize intGroupCount. This MUST be placed in the On Print event:
'reinitialize intGroupCount to zero
intGroupCount = 0
HTH, [pc2]
Randy Smith
California Teachers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top