Page total in Header of report. Uses las page total. How to fix?

G

Gerard Mears

Hi,

I have the following report set up.

Page Header information

Page Detail

Page Footer.

In the footer I have calculated the total for a field for each page.
That is, it adds the total amount for field one on page 1 then resets
to zero and recalculated the total for page 2 and so on. I use VB
code in the detail part of the the form to calculate this total.

The page footer VB code then populates an unbound control with the
total from the detail section. I need the same total in the Page
Header as well.

The problem is that the page header total always displays the previous
pages total. I have tried using =[total from footer control] and
populating the total in the header from the VBcode in the footer.
Both provide incorrect results.

Anyone know of a way around this?

Thanks
 
N

Nikos Yannacopoulos

Gerard,

I have done this before like this:

I have an unbound textbox in the page header section, called txtPgTotal1,
and my page total in control txtPgTotal (invisible) in the page footer
section; I use a line of code:

Me.txtPgTotal1 = Me.txtPgTotal

in the page footer's Format event, and it does the trick.

HTH,
Nikos
 
M

Marshall Barton

Gerard said:
I have the following report set up.

Page Header information

Page Detail

Page Footer.

In the footer I have calculated the total for a field for each page.
That is, it adds the total amount for field one on page 1 then resets
to zero and recalculated the total for page 2 and so on. I use VB
code in the detail part of the the form to calculate this total.

The page footer VB code then populates an unbound control with the
total from the detail section. I need the same total in the Page
Header as well.

The problem is that the page header total always displays the previous
pages total. I have tried using =[total from footer control] and
populating the total in the header from the VBcode in the footer.
Both provide incorrect results.


This is tricky because the Page Header is formatted and
printed before the Page Footer is formatted.

To do this you have to force the report to be formatted
twice by having a page header or footer text box with an
expression that includes Pages (the usual =Page & " of "
Pages will do just fine).

You can then save the calculated page total in the footer's
Format event and retrieve the total in the header's Print
event where the saved totals will be correct the second time
through.

Here's some sample code:
----------------------------------------------------
Private intPageTotal(500) As Integer

Private Sub PageFooterSection_Format(Cancel As Integer,
FormatCount As Integer)
Me.txtFtr = Me.txtRunTotal
intPageTotal(Me.Page) = Me.txtRunTotal
End Sub

Private Sub PageHeaderSection_Print(Cancel As Integer,
PrintCount As Integer)
Me.txtHdr = intPageTotal(Me.Page)
End Sub
 
M

Marshall Barton

I can't get that to work Nikos. The way I understand how
reports work, the Page Header is formatted (and printed)
before the code in the Page Footer executes.

See my reply to Gerard for what I finally did to get the
footer total to appear in the header.
--
Marsh
MVP [MS Access]



Nikos said:
I have done this before like this:

I have an unbound textbox in the page header section, called txtPgTotal1,
and my page total in control txtPgTotal (invisible) in the page footer
section; I use a line of code:

Me.txtPgTotal1 = Me.txtPgTotal

in the page footer's Format event, and it does the trick.

Gerard Mears said:
I have the following report set up.

Page Header information
Page Detail
Page Footer.

In the footer I have calculated the total for a field for each page.
That is, it adds the total amount for field one on page 1 then resets
to zero and recalculated the total for page 2 and so on. I use VB
code in the detail part of the the form to calculate this total.

The page footer VB code then populates an unbound control with the
total from the detail section. I need the same total in the Page
Header as well.

The problem is that the page header total always displays the previous
pages total. I have tried using =[total from footer control] and
populating the total in the header from the VBcode in the footer.
Both provide incorrect results.
 
N

Nikos Yannacopoulos

Marsh,

You are absolutely right... I can't get it to work either now, I just can't
figure out how I did it while testing before I replied to Gerard. Timing of
events is certainly the way you say, and that is proven by the fact that I
get the previous page's total in each page's header the way I did it.

Thanks for resolving this.

Nikos

Marshall Barton said:
I can't get that to work Nikos. The way I understand how
reports work, the Page Header is formatted (and printed)
before the code in the Page Footer executes.

See my reply to Gerard for what I finally did to get the
footer total to appear in the header.
--
Marsh
MVP [MS Access]



Nikos said:
I have done this before like this:

I have an unbound textbox in the page header section, called txtPgTotal1,
and my page total in control txtPgTotal (invisible) in the page footer
section; I use a line of code:

Me.txtPgTotal1 = Me.txtPgTotal

in the page footer's Format event, and it does the trick.

Gerard Mears said:
I have the following report set up.

Page Header information
Page Detail
Page Footer.

In the footer I have calculated the total for a field for each page.
That is, it adds the total amount for field one on page 1 then resets
to zero and recalculated the total for page 2 and so on. I use VB
code in the detail part of the the form to calculate this total.

The page footer VB code then populates an unbound control with the
total from the detail section. I need the same total in the Page
Header as well.

The problem is that the page header total always displays the previous
pages total. I have tried using =[total from footer control] and
populating the total in the header from the VBcode in the footer.
Both provide incorrect results.
 

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