Re: Page totals error in report - doesn't add correctly
- From: Marshall Barton <marshbarton@xxxxxxxxxx>
- Date: Tue, 16 May 2006 00:17:41 -0500
Geoff wrote:
I am trying to print the total number of hours billed to a client in a
report. Initially this was displayed in a textbox with the source set to the
expression "=Sum([Hours]). This works fine on the one report which displays
the decimals correctly in the report footer, but won't work at all on the
other report where the total should read 266.85 hours but instead will only
display 266 hours.
Then I used Allen Browne's Page Total code and discovered that the problem
is caused by the total hours for the first page which are displayed
incorrectly (adds up to 10 whereas it should be 10.83). The total hours all
display correctly in the group footers but won't do so in the report footer.
All Totals text boxes properties are set to General number with 2 decimal
places - as is the data in the source query and table.
Why does one report work fine and the other not? I've even completely
rebuilt a new report from the one that works, but to no avail - still gives
the wrong total. Can anyone help? Thanks
Allen Browne's code that I used was as follows:
Option Compare Database
Dim HoursTotal As Long
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then HoursTotal = HoursTotal + Nz(Me.Hours, 0)
End Sub
Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As
Integer)
Me.PageTotal = HoursTotal
End Sub
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As
Integer)
HoursTotal = 0
End Sub
That code that you're using isn't supposed to do what you
say you want. I suspect that there may be more to using
that code than just copying it, because there are several
caveats to using an event procedure to calculate a total.
In almost all cases that code can not reliably calculate a
correct total.
Using the Sum function is the right way to do this if Hours
is a field in the report's recordsource table/query.
(Otherwise, you can use a RunningSum text box to add up the
total.)
The first thing I would suspect is that the Hours is somehow
being converted to an integer. To check this, try setting
the Hours text box in the detail section and all the group
and report footer text boxes to use the format 0.000000000
so you can see the whole value.
The next thing to check is the actual, not the formatted,
values in the recordsource table/query. Applying a format
to the table and query just obscurs the values used in the
calculations.
--
Marsh
MVP [MS Access]
.
- Follow-Ups:
- Prev by Date: Re: Output only Last Record from a Report?
- Next by Date: Re: >> alternate page print
- Previous by thread: Re: Create conditional formating of in reports
- Next by thread: Re: Page totals error in report - doesn't add correctly
- Index(es):
Relevant Pages
|
Loading