Community Pick: Many members of our community have endorsed this article.
Editor's Choice: This article has been selected by our editors as an exceptional contribution.

Page Headers on Sub-Reports and Custom Page Headers

Page headers and footers are naturally very useful. It would have been unthinkable to create a reporting engine without them. However, they are not printed on sub-reports, the rationale being that the main report provides them. If one needs sub-report page headers or needs to customise them in any other way not allowed for the built-in section, there is a trick to create one's own.

Group headers (but not footers) have the option “Repeat Section: yes”. This means that the header will become an additional page header over all pages of that group. Now if there was a way to create one single group...

It's quite simple:

Open the report in design view,
activate the “Sorting and Grouping” sheet,
enter as first “Field/Expression”: =1
set “Group Header: yes”,
display the group's properties,
set “Repeat Section: yes”.
custom page headerThat's it. The header will behave almost like a page header: it can include page numbering expressions like “=Page” or “=Page & ' of ' & Pages”, labels, horizontal rulers, etc. If there is also a regular page header, it will always come second. The differences are that:

it will print when the report is a sub-report,
it can grow and shrink,
it appears after the report header on the first page.
If the last point is a problem, the page header can be modified to mimic the custom page header, which can be turned off on the first page. This trick is not explained in detail here, but one solution is the following “on print” event hander:
Private Sub MyPageHeader_Print(Cancel As Integer, PrintCount As Integer)
                          Cancel = (Page = 1)
                      End Sub

Open in new window

The question about page headers in sub-reports is one of those recurring questions on Experts Exchange: why do they disappear? how do I get them back? The next time, I will provide a link to this page for the long version of the answer.

Markus G Fischer

This article is part of the EE-book unrestricted Access.

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.