Print page footer only when needed

C

Carl Rapson

I've got a report that may or may not exceed one page, including the report
footer. I would like to include a page footer on the first page only if the
report exceeds one page. I set the report PageFooter property to "Not with
Rpt Ftr", which prevents the page footer from printing on the second page
when there is one. However, it appears that the report really wants to print
the page footer section, whether it is needed or not. For example, on a
report that does NOT exceed one page, including the report footer, the page
footer is still printed, which causes the report footer to wrap to the
second page. If the page footer didn't print, the entire report would fit on
one page (I've tested it). Is there any way to prevent the page footer
section from printing if it isn't really needed?

Thanks for any assistance,

Carl Rapson
 
G

Guest

Carl,

Add this code to the report's module

Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
If Me.Pages = 1 Then Cancel = True
End Sub

This will prevent the footer from printing if the report is only one page.
The cancel = true really means do not print (create the fotmat)

If this solves your problem then please check the answered box.
 
C

Carl Rapson

Thanks for the suggestion. Unfortunately, when I placed the code in the
ReportFooter_Format section, I still get the page footer on single-page
reports, causing the report footer to wrap to the next page. I stepped
through the code, and the ReportFooter section was called twice - once with
the Pages property set to zero, and once with the Pages property set to 2. I
tried changing the If statement to

If Me.Pages = 0 Then Cancel = True

but the page footer still printed on the first page. I also tried the
following line in the ReportFooter section:

If (Me.Pages = 0) Or (Me.Page < Me.Pages) Then Cancel = True

When I did that, the page footer didn't print on the first page, but the
space for the page footer was left blank at the bottom of the first page -
and the report footer still wrapped to the next page. If I remove the Page
footer section completely from my report, the report prints in a single page
(including the report footer).

Might you have any other ideas? Thanks,

Carl Rapson
 
G

Guest

Carl,

I think that access is a 2 pass report system. This means that the system
tries to generate the report twice for formatting. This is a long shot but
.... can you tell how much data is going to print? Is it possible to do a row
count on the detail section and determine when you are going to run over to a
new page. If you can derermine that, maybe on open event could count the
rows from the query and turn on/off the footer. Please let me know if this
works.

Best of luck ...
 
M

Marshall Barton

Carl said:
I've got a report that may or may not exceed one page, including the report
footer. I would like to include a page footer on the first page only if the
report exceeds one page. I set the report PageFooter property to "Not with
Rpt Ftr", which prevents the page footer from printing on the second page
when there is one. However, it appears that the report really wants to print
the page footer section, whether it is needed or not. For example, on a
report that does NOT exceed one page, including the report footer, the page
footer is still printed, which causes the report footer to wrap to the
second page. If the page footer didn't print, the entire report would fit on
one page (I've tested it). Is there any way to prevent the page footer
section from printing if it isn't really needed?


I think you have to do this in the Page Header Format event
to be able to reclaim the space reserved for the page
footer.

Me.Section(5).Visible = (Me.Page = 1 And Me.Pages > 1)

Note that Me.Pages will not work unless you have a text box
somewhere on the report that refers to Pages.
 
C

Carl Rapson

Stewart,

Thanks again for the suggestion. Unfortunately, my Detail section isn't that
simple. It consists of a series of subreports, each of which Can Grow. I
don't know how to tell beforehand how many "detail lines" I have, since I
don't really have detail lines.

Carl Rapson
 
C

Carl Rapson

Marshall Barton said:
I think you have to do this in the Page Header Format event
to be able to reclaim the space reserved for the page
footer.

Me.Section(5).Visible = (Me.Page = 1 And Me.Pages > 1)

Note that Me.Pages will not work unless you have a text box
somewhere on the report that refers to Pages.

Marshall,

Thanks for the suggestion. I placed the code in the PageHeaderSection_Format
event (I changed Section(5) to Section(acPageFooter)), with the following
results:

For reports that are only one page, I got a single page, but the number of
pages still seems to be 2. I have a text box in the report footer section
with a Control Source of "=[Page] of [Pages]", and it displays as "Page 1 of
2". Otherwise, the report printed the way I want it to.

For reports that are more than one page, I don't get the page footer section
at all on the first page. That makes sense, because the line I added to the
page header section prevents the page footer from printing, even when it
legitimately should print. Unfortunately, I don't want this to happen.

What I need is for the page footer section to print on the first page only
when the report would have more than one page without the page footer. If
the report would have only one page without the page footer, I don't want
the page footer to print. But the report seems to be reserving space for the
page footer, whether it's needed or not. I set the report's Page Footer
property to Not with Rpt Hdr, but it appears that Access really wants to
print the page footer at least once, even if it isn't needed. I welcome any
suggestions about how to solve this.

One thing I'm going to try is a redesign of my report, to place all of the
subreports now in the Detail section into group header/footer sections. I
want to see if that might have an effect on this problem.

Thanks again for your assistance,

Carl Rapson
 
M

Marshall Barton

Carl said:
I think you have to do this in the Page Header Format event
to be able to reclaim the space reserved for the page
footer.

Me.Section(5).Visible = (Me.Page = 1 And Me.Pages > 1)

Note that Me.Pages will not work unless you have a text box
somewhere on the report that refers to Pages.

Thanks for the suggestion. I placed the code in the PageHeaderSection_Format
event (I changed Section(5) to Section(acPageFooter)), with the following
results:

For reports that are only one page, I got a single page, but the number of
pages still seems to be 2. I have a text box in the report footer section
with a Control Source of "=[Page] of [Pages]", and it displays as "Page 1 of
2". Otherwise, the report printed the way I want it to.

For reports that are more than one page, I don't get the page footer section
at all on the first page. That makes sense, because the line I added to the
page header section prevents the page footer from printing, even when it
legitimately should print. Unfortunately, I don't want this to happen.

What I need is for the page footer section to print on the first page only
when the report would have more than one page without the page footer. If
the report would have only one page without the page footer, I don't want
the page footer to print. But the report seems to be reserving space for the
page footer, whether it's needed or not. I set the report's Page Footer
property to Not with Rpt Hdr, but it appears that Access really wants to
print the page footer at least once, even if it isn't needed. I welcome any
suggestions about how to solve this.

One thing I'm going to try is a redesign of my report, to place all of the
subreports now in the Detail section into group header/footer sections. I
want to see if that might have an effect on this problem.

Just in case something was lost in translation, you need to
post the code you are actually using.

The code I posted should work if the report has more than
one page.

It should also work if there is only one page.

But, the situation where the last page has Page 1 of 2 is a
problem. Let's try beefing up the code:

Me.Section(5).Visible = (Me.Page = 1 _
And (Me.Pages > 1 Or Me.Pages = 0)
 
C

Carl Rapson

Marshall Barton said:
Carl said:
Carl Rapson wrote:
I've got a report that may or may not exceed one page, including the
report
footer. I would like to include a page footer on the first page only if
the
report exceeds one page. I set the report PageFooter property to "Not
with
Rpt Ftr", which prevents the page footer from printing on the second
page
when there is one. However, it appears that the report really wants to
print
the page footer section, whether it is needed or not. For example, on a
report that does NOT exceed one page, including the report footer, the
page
footer is still printed, which causes the report footer to wrap to the
second page. If the page footer didn't print, the entire report would
fit
on
one page (I've tested it). Is there any way to prevent the page footer
section from printing if it isn't really needed?


I think you have to do this in the Page Header Format event
to be able to reclaim the space reserved for the page
footer.

Me.Section(5).Visible = (Me.Page = 1 And Me.Pages > 1)

Note that Me.Pages will not work unless you have a text box
somewhere on the report that refers to Pages.

Thanks for the suggestion. I placed the code in the
PageHeaderSection_Format
event (I changed Section(5) to Section(acPageFooter)), with the following
results:

For reports that are only one page, I got a single page, but the number of
pages still seems to be 2. I have a text box in the report footer section
with a Control Source of "=[Page] of [Pages]", and it displays as "Page 1
of
2". Otherwise, the report printed the way I want it to.

For reports that are more than one page, I don't get the page footer
section
at all on the first page. That makes sense, because the line I added to
the
page header section prevents the page footer from printing, even when it
legitimately should print. Unfortunately, I don't want this to happen.

What I need is for the page footer section to print on the first page only
when the report would have more than one page without the page footer. If
the report would have only one page without the page footer, I don't want
the page footer to print. But the report seems to be reserving space for
the
page footer, whether it's needed or not. I set the report's Page Footer
property to Not with Rpt Hdr, but it appears that Access really wants to
print the page footer at least once, even if it isn't needed. I welcome
any
suggestions about how to solve this.

One thing I'm going to try is a redesign of my report, to place all of the
subreports now in the Detail section into group header/footer sections. I
want to see if that might have an effect on this problem.

Just in case something was lost in translation, you need to
post the code you are actually using.

The code I posted should work if the report has more than
one page.

It should also work if there is only one page.

But, the situation where the last page has Page 1 of 2 is a
problem. Let's try beefing up the code:

Me.Section(5).Visible = (Me.Page = 1 _
And (Me.Pages > 1 Or Me.Pages = 0)

Marshall,

Here is the code I added to my PageHeaderSection_Format event:

If ((Me.Page = 1) And ((Me.Pages > 1) Or (Me.Pages = 0))) Then
Me.Section(acPageFooter).Visible = False
End If

I changed the "5" to "acPageFooter", because the on-line help indicated that
the Page Footer section is actually 4, not 5. I thought that using the
constant would be better than a hard-coded value. However, using values of
both 4 and 5 didn't seem to make any difference in which sections printed.

With the above code in my page header section, I still get the page footer
printing on a report that should only be one page. I tested this by
completely removing the page footer section from the report; when I did, the
report printed on a single page (although I then have the problem of the
report saying "Page 1 of 2", even though there's only one page).

One thing I have learned is that this problem may be related to the height
of the report. My top and bottom margins are set to 0.166", which I suspect
may be too little for the printer I am using. I found that removing a
segment of my Detail section allows the report to print on a single page.
This seems inconsistent with the report printing on a single page when the
page footer is removed. I may have to redesign the form to make this work.

Thanks for your assistance,

Carl Rapson
 
M

Marshall Barton

Carl said:
"Marshall Barton" wrote
Carl said:
Carl Rapson wrote:
I've got a report that may or may not exceed one page, including the
report
footer. I would like to include a page footer on the first page only if
the
report exceeds one page. I set the report PageFooter property to "Not
with
Rpt Ftr", which prevents the page footer from printing on the second
page
when there is one. However, it appears that the report really wants to
print
the page footer section, whether it is needed or not. For example, on a
report that does NOT exceed one page, including the report footer, the
page
footer is still printed, which causes the report footer to wrap to the
second page. If the page footer didn't print, the entire report would
fit
on
one page (I've tested it). Is there any way to prevent the page footer
section from printing if it isn't really needed?


I think you have to do this in the Page Header Format event
to be able to reclaim the space reserved for the page
footer.

Me.Section(5).Visible = (Me.Page = 1 And Me.Pages > 1)

Note that Me.Pages will not work unless you have a text box
somewhere on the report that refers to Pages.


Thanks for the suggestion. I placed the code in the
PageHeaderSection_Format
event (I changed Section(5) to Section(acPageFooter)), with the following
results:

For reports that are only one page, I got a single page, but the number of
pages still seems to be 2. I have a text box in the report footer section
with a Control Source of "=[Page] of [Pages]", and it displays as "Page 1
of
2". Otherwise, the report printed the way I want it to.

For reports that are more than one page, I don't get the page footer
section
at all on the first page. That makes sense, because the line I added to
the
page header section prevents the page footer from printing, even when it
legitimately should print. Unfortunately, I don't want this to happen.

What I need is for the page footer section to print on the first page only
when the report would have more than one page without the page footer. If
the report would have only one page without the page footer, I don't want
the page footer to print. But the report seems to be reserving space for
the
page footer, whether it's needed or not. I set the report's Page Footer
property to Not with Rpt Hdr, but it appears that Access really wants to
print the page footer at least once, even if it isn't needed. I welcome
any
suggestions about how to solve this.

One thing I'm going to try is a redesign of my report, to place all of the
subreports now in the Detail section into group header/footer sections. I
want to see if that might have an effect on this problem.

Just in case something was lost in translation, you need to
post the code you are actually using.

The code I posted should work if the report has more than
one page.

It should also work if there is only one page.

But, the situation where the last page has Page 1 of 2 is a
problem. Let's try beefing up the code:

Me.Section(5).Visible = (Me.Page = 1 _
And (Me.Pages > 1 Or Me.Pages = 0)

Marshall,

Here is the code I added to my PageHeaderSection_Format event:

If ((Me.Page = 1) And ((Me.Pages > 1) Or (Me.Pages = 0))) Then
Me.Section(acPageFooter).Visible = False
End If

I changed the "5" to "acPageFooter", because the on-line help indicated that
the Page Footer section is actually 4, not 5. I thought that using the
constant would be better than a hard-coded value. However, using values of
both 4 and 5 didn't seem to make any difference in which sections printed.

With the above code in my page header section, I still get the page footer
printing on a report that should only be one page. I tested this by
completely removing the page footer section from the report; when I did, the
report printed on a single page (although I then have the problem of the
report saying "Page 1 of 2", even though there's only one page).

One thing I have learned is that this problem may be related to the height
of the report. My top and bottom margins are set to 0.166", which I suspect
may be too little for the printer I am using. I found that removing a
segment of my Detail section allows the report to print on a single page.
This seems inconsistent with the report printing on a single page when the
page footer is removed. I may have to redesign the form to make this work.


The top and bottom margins should not be impacting this
situation. If your printer (driver) accepts the settings,
then you will only run into problems when you use a
different printer that requires larger margins.

Back to the original problem. I created a report that
reproduces what you are trying to do and could not get it to
work at all in AXP. This is different from what I remember
in A97 and earlier. Failing memory aside, I think Access
was changed somewhere along the line so that if the page
footer is made visible anywhere in the report, the space it
consumes is reserved on all pages.

Bottom line, unless someone else has another approach, I
think you are out of luck on this one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top