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] [pc2] [pc2]](/data/assets/smilies/pc2.gif)
Randy Smith
California Teachers Association