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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group Section Heading to show correctly for continuation pages

How To

Group Section Heading to show correctly for continuation pages

by  LittleSmudge  Posted    (Edited  )
I had a report where I wanted Group Sections that continue from one page to another get "Group Section Header Continuation" titles showing at the top of the page.

I tried to use the "Sales per Year" demo in Northwind but it doesn't work correctly if the new Group Section just fits it's Header on the bottom of a page and then Retreats to the next page.

This solution does work correctly.

1) Put Group Section Header labels in the Group Section Header as usual.
2) Put Group Section continuation labels in the Page Header.

3) In the Grouping and Sorting window set the Group Section's Keeps Together property to WHOLE GROUP
( This is an important step and it won't function with this setting )

4) Name the Group header BlockHeader or edit the following code to the name of your Group Header section.

5) Place the following code into the Report's Code Module
Code:
Option Compare Database
Option Explicit

' The code on this report is all to do with ensuring that the 'Page Header'
' is printed when a Block's data continues from one page to another
' but does not print when a new Block's data starts at the top of a page.

' mblnEnableHeaderFormat is needed because near the end of a page
' if the Block's section Header could just fit on the page but the rest
' of the data does not, the sequence of events is
' Header_Format
' Header_Retreat
' Header_Format ( BUT Format count is still 1  !!! )
' Print New Page
' So the Header_Retreat needs to prevent the next Header_Format from allowing
' the continuation header to be displayed.
' PageHeader_Format then resets this prevention after the first page in the section


Dim mblnHidePageHeader As Boolean
Dim mblnEnableHeaderFormat As Boolean

Private Sub BlockHeader_Format(Cancel As Integer, FormatCount As Integer)
If mblnEnableHeaderFormat Then
    mblnHidePageHeader = False
End If
End Sub

Private Sub BlockHeader_Retreat()
mblnHidePageHeader = True
mblnEnableHeaderFormat = False  ' Prevent Header_Format from setting HPH to False
End Sub

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Cancel = mblnHidePageHeader     ' THE line that actually does the Show/NotShow work
mblnEnableHeaderFormat = True   ' Reset after first page of any section
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
'Initialisation
mblnHidePageHeader = True
mblnEnableHeaderFormat = True
End Sub


I've used Module level variables in this instead of the TextBox Control stuck on the Report that Northwind uses because I think its neater and a lot easier for other people to see what is going on.


Enjoy !


Footnote
From a feedback comment from Hfloyd
The GroupHeader Property "Force New Page" MUST be set to "None".
At first I had it set to "Before Section" (since I wanted the Group
header to begin at the top of the page), but the code didn't propery
display the headers. When I changed it to "None" it worked perfectly - and
still had the group headers beginning at the top of pages.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top