473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Report: Running Total Problem

Hi

I am trying to calculate a running total of a calculated textbox
(tbAtStandard) in GroupFooter1 for placement in a textbox
(tbTotalAtStandard) on my report in Groupfooter0.

The problem that I am having is that sometimes the correct total shows
up in print preview and sometimes it doesn't. Sometimes it is higher
and sometimes it is lower (than the correct amount) and I cannot make
any sense of the difference. The difference seemingly does not tie
into anything on the report (e.g. double counting an item or leaving
off an item). Another anomaly is that the print preview and the actual
printing sometimes produce different results, again without any
pattern (but sometimes correct).

The code I am using seems to me to be quite simple and is as follows:

Option Compare Database
Dim vbatbAtStandard As Double
Dim vbatbAtCost As Double
Private Sub GroupFooter0_Print(Cancel As Integer, PrintCount As
Integer)
'------ post the running sum to the report and zero the variable
for next group -------
Me!tbTotalAtStandard = vbatbAtStandard
vbatbAtStandard = 0
'---------------------------------------------------------------------------
Me!tbTotalAtCost = vbatbAtCost
vbatbAtCost = 0
End Sub

Private Sub GroupFooter1_Print(Cancel As Integer, PrintCount As
Integer)
If PrintCount = 1 Then
'------- calculate the running sum --------
vbatbAtStandard = vbatbAtStandard + Me!tbAtStandard
'------------------------------------------
vbatbAtCost = vbatbAtCost + Me!tbAtCost
End If
End Sub

Any help would be much appreciated.

Regards,
Bill Dika
Nov 12 '05 #1
4 10319
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ugh . . . I've never had any success using VBA to calculate totals in
reports. I've found that using a TextBox's RunningSum property is
simpler & more accurate.

== Simple totals

Since you want to get the Sum of a calculated control you can do
something like this:

Detail Section

ControlSource: Data1 Data2 =Data1+Data2
Name: Data1 Data2 txtDetailTotal

Group Footer Section

ControlSource: =Sum(Data1) =Sum(Data2) =txtSumData1+txtSumData2
Name: txtSumData1 txtSumData2 txtSumAll
== Running Sum totals

Say I wanted to keep a running sum of the =Data1+Data2 calculation
(txtDetailTotal control). I'd set up another TextBox control's
properties like this in the Detail section:

Name: txtDetailRunSum
ControlSource: =txtDetailTotal
Visible: False
RunningSum: Over All

Then in the group footer section I'd have a TextBox set up like this:

ControlSource: =txtDetailRunSum
Visible: True

This control would show the running sum for all groupings.

Read the Access help articles on "RunningSum Property" for more info.

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP7WzEoechKqOuFEgEQIvcwCgvqkhn4luFwWdaegd/UF50DtKg2UAoNX4
DZeon75WOL5v7Mk4CpK6ITPf
=ZoA1
-----END PGP SIGNATURE-----
Bill Dika wrote:
Hi

I am trying to calculate a running total of a calculated textbox
(tbAtStandard) in GroupFooter1 for placement in a textbox
(tbTotalAtStandard) on my report in Groupfooter0.

The problem that I am having is that sometimes the correct total shows
up in print preview and sometimes it doesn't. Sometimes it is higher
and sometimes it is lower (than the correct amount) and I cannot make
any sense of the difference. The difference seemingly does not tie
into anything on the report (e.g. double counting an item or leaving
off an item). Another anomaly is that the print preview and the actual
printing sometimes produce different results, again without any
pattern (but sometimes correct).

The code I am using seems to me to be quite simple and is as follows:

Option Compare Database
Dim vbatbAtStandard As Double
Dim vbatbAtCost As Double
Private Sub GroupFooter0_Print(Cancel As Integer, PrintCount As
Integer)
'------ post the running sum to the report and zero the variable
for next group -------
Me!tbTotalAtStandard = vbatbAtStandard
vbatbAtStandard = 0
'---------------------------------------------------------------------------
Me!tbTotalAtCost = vbatbAtCost
vbatbAtCost = 0
End Sub

Private Sub GroupFooter1_Print(Cancel As Integer, PrintCount As
Integer)
If PrintCount = 1 Then
'------- calculate the running sum --------
vbatbAtStandard = vbatbAtStandard + Me!tbAtStandard
'------------------------------------------
vbatbAtCost = vbatbAtCost + Me!tbAtCost
End If
End Sub

Any help would be much appreciated.

Regards,
Bill Dika

Nov 12 '05 #2
On 14 Nov 2003 12:28:02 -0800, bd*****@yahoo.com (Bill Dika) wrote:

It seems you're writing code to calculate the sum. This code may be
called multiple times by Access. That's what the PrintCount argument
is for. Set a breakpoint and you'll see what I mean. Even "if
PrintCount = 1" to me seems a bit too scary. For example your function
may be called again with PrintCount=1 if you first preview the report
and then print it from there.

The standard way of calculating a running sum is to specify this at
design time in a control. See the RunningSum property of a textbox.
Try that first.

-Tom.

Hi

I am trying to calculate a running total of a calculated textbox
(tbAtStandard) in GroupFooter1 for placement in a textbox
(tbTotalAtStandard) on my report in Groupfooter0.

The problem that I am having is that sometimes the correct total shows
up in print preview and sometimes it doesn't. Sometimes it is higher
and sometimes it is lower (than the correct amount) and I cannot make
any sense of the difference. The difference seemingly does not tie
into anything on the report (e.g. double counting an item or leaving
off an item). Another anomaly is that the print preview and the actual
printing sometimes produce different results, again without any
pattern (but sometimes correct).

The code I am using seems to me to be quite simple and is as follows:

Option Compare Database
Dim vbatbAtStandard As Double
Dim vbatbAtCost As Double
Private Sub GroupFooter0_Print(Cancel As Integer, PrintCount As
Integer)
'------ post the running sum to the report and zero the variable
for next group -------
Me!tbTotalAtStandard = vbatbAtStandard
vbatbAtStandard = 0
'---------------------------------------------------------------------------
Me!tbTotalAtCost = vbatbAtCost
vbatbAtCost = 0
End Sub

Private Sub GroupFooter1_Print(Cancel As Integer, PrintCount As
Integer)
If PrintCount = 1 Then
'------- calculate the running sum --------
vbatbAtStandard = vbatbAtStandard + Me!tbAtStandard
'------------------------------------------
vbatbAtCost = vbatbAtCost + Me!tbAtCost
End If
End Sub

Any help would be much appreciated.

Regards,
Bill Dika


Nov 12 '05 #3
Thanks guys for responding to my post.

MGFoster & Tom

My application is a time keeping system.

My GroupFooter1 is Employee. In the Detail Section I show start and
end times for given dates. In GroupFooter1 I total up the hours using
a Sum(EndTime-StarTime) and then I have a calculated control in
GroupFooter1 that uses a DLookup to get the charge rate for that
employee and multiply it times the total hours for that employee.

Something like:
GroupFooter1
Control Name = tbAtStandard
Control Source = DLookup(EmployeeRate) X Sum(EndTime-StartTime)
This seems to work fine.

The problem comes in accumulating tbAtStandard for all employees in
GroupFooter0 which is Client. I'm not sure if and how I can use the
RunningSum property to get the result. If I set up in GroupFooter0 a
textbox with control source = sum(tbAtStandard), when I run the report
it asks me to input tbAtStandard.

That is why I have tried to use code to keep a running total of
tbAtStandard. Since my first post I have tried putting my code into
the Format events instead of the Print events but I still don't get
the correct results.

MGFoster
I don't think I can use your suggestion which relies on calculations
in the detail section because the EmployeeRate changes with each new
GroupFooter1.

Am I missing something obvious?

Many thanks.

Regards,
Bill Dika

Tom van Stiphout <to*****@no.spam.cox.net> wrote in message news:<br********************************@4ax.com>. ..
On 14 Nov 2003 12:28:02 -0800, bd*****@yahoo.com (Bill Dika) wrote:

It seems you're writing code to calculate the sum. This code may be
called multiple times by Access. That's what the PrintCount argument
is for. Set a breakpoint and you'll see what I mean. Even "if
PrintCount = 1" to me seems a bit too scary. For example your function
may be called again with PrintCount=1 if you first preview the report
and then print it from there.

The standard way of calculating a running sum is to specify this at
design time in a control. See the RunningSum property of a textbox.
Try that first.

-Tom.

Hi

I am trying to calculate a running total of a calculated textbox
(tbAtStandard) in GroupFooter1 for placement in a textbox
(tbTotalAtStandard) on my report in Groupfooter0.

The problem that I am having is that sometimes the correct total shows
up in print preview and sometimes it doesn't. Sometimes it is higher
and sometimes it is lower (than the correct amount) and I cannot make
any sense of the difference. The difference seemingly does not tie
into anything on the report (e.g. double counting an item or leaving
off an item). Another anomaly is that the print preview and the actual
printing sometimes produce different results, again without any
pattern (but sometimes correct).

The code I am using seems to me to be quite simple and is as follows:

Option Compare Database
Dim vbatbAtStandard As Double
Dim vbatbAtCost As Double
Private Sub GroupFooter0_Print(Cancel As Integer, PrintCount As
Integer)
'------ post the running sum to the report and zero the variable
for next group -------
Me!tbTotalAtStandard = vbatbAtStandard
vbatbAtStandard = 0
'---------------------------------------------------------------------------
Me!tbTotalAtCost = vbatbAtCost
vbatbAtCost = 0
End Sub

Private Sub GroupFooter1_Print(Cancel As Integer, PrintCount As
Integer)
If PrintCount = 1 Then
'------- calculate the running sum --------
vbatbAtStandard = vbatbAtStandard + Me!tbAtStandard
'------------------------------------------
vbatbAtCost = vbatbAtCost + Me!tbAtCost
End If
End Sub

Any help would be much appreciated.

Regards,
Bill Dika

Nov 12 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Try this:

In GroupFooter1 section put a TextBox control next the control
"tbAtStandard." Set its Properties like so:

Name: txtSumStandard
Control Source: =[tbAtStandard]
Running Sum: Over Group
Visible: No

The "Over Group" running sum means each time the footer/header section
changes to a new grouping item the running sum is reset to zero.
"Over All" means the running sum is kept for the total report. See
the "RunningSum Property" Help article for more info.

In the GroupFooter0 section put a TextBox in the same column space as
the control "tbAtStandard." Set its Properties like so:

Name: txtFooter_SumStandard
Control Source: =[txtSumStandard]
Running Sum: No
Visible: Yes

The Running Sum property can be a PITA until understood. Even now, I
have to fiddle around w/ Running Sum reports until I get them right.

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP7sU+4echKqOuFEgEQJ9OgCcCYdRdKcBbF+pMDBvl/noe5TzIzsAmwX8
gjX2aZq/rrQv+VzBTp1jo7oR
=ZL2Y
-----END PGP SIGNATURE-----

Bill Dika wrote:
Thanks guys for responding to my post.

MGFoster & Tom

My application is a time keeping system.

My GroupFooter1 is Employee. In the Detail Section I show start and
end times for given dates. In GroupFooter1 I total up the hours using
a Sum(EndTime-StarTime) and then I have a calculated control in
GroupFooter1 that uses a DLookup to get the charge rate for that
employee and multiply it times the total hours for that employee.

Something like:
GroupFooter1
Control Name = tbAtStandard
Control Source = DLookup(EmployeeRate) X Sum(EndTime-StartTime)
This seems to work fine.

The problem comes in accumulating tbAtStandard for all employees in
GroupFooter0 which is Client. I'm not sure if and how I can use the
RunningSum property to get the result. If I set up in GroupFooter0 a
textbox with control source = sum(tbAtStandard), when I run the report
it asks me to input tbAtStandard.

That is why I have tried to use code to keep a running total of
tbAtStandard. Since my first post I have tried putting my code into
the Format events instead of the Print events but I still don't get
the correct results.

MGFoster
I don't think I can use your suggestion which relies on calculations
in the detail section because the EmployeeRate changes with each new
GroupFooter1.

Am I missing something obvious?

Many thanks.

Regards,
Bill Dika

Tom van Stiphout <to*****@no.spam.cox.net> wrote in message news:<br********************************@4ax.com>. ..
On 14 Nov 2003 12:28:02 -0800, bd*****@yahoo.com (Bill Dika) wrote:

It seems you're writing code to calculate the sum. This code may be
called multiple times by Access. That's what the PrintCount argument
is for. Set a breakpoint and you'll see what I mean. Even "if
PrintCount = 1" to me seems a bit too scary. For example your function
may be called again with PrintCount=1 if you first preview the report
and then print it from there.

The standard way of calculating a running sum is to specify this at
design time in a control. See the RunningSum property of a textbox.
Try that first.

-Tom.
Hi

I am trying to calculate a running total of a calculated textbox
(tbAtStandard) in GroupFooter1 for placement in a textbox
(tbTotalAtStandard) on my report in Groupfooter0.

< snip >

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Darren | last post by:
I have a report with one level of grouping and a running sum field in the detail section of the report. When I make the running sum field visible, I can see that it increases the count by 1 for...
2
by: Pea | last post by:
Hello, I have a report with groups, subgroups and counts. I'm trying to give a total for each group and used the RunningSum property by group. But I find that it's running throughout the report....
8
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I...
0
by: galkas | last post by:
Hello I have got a report, which can run on 3 groups of data: College Faculty School Faculty contains schools. College contains faculties. The report can be run for college, then it includes...
3
by: Pecanfan | last post by:
Hi, I've got an access report which contains a sub-report. The sub-report contains various items in a group Footer which culminates in a running sum text box called txtGrandTotal. I want to...
7
by: SueB | last post by:
Greetings. I have a report based on the following query (hang in there ... it's quite long): SELECT Year(.) AS Yr, tblEvents.eventID, tblEvents.eventname, tblEvents.eventhost,...
3
by: Jimmy | last post by:
Is there a way to force access to wait a specified time before making a calculation? On my report there is a subreport with a number of calculation on it. One if which is a count of certain...
7
by: Sunil Korah | last post by:
Hi, I haven't used access reports much. I have a problem in getting the total of a group. I have 3 fields, ProgName (Program name), Pname (Participant's name) and PCategory (Participant...
4
by: lorirobn | last post by:
Hi, I have a report displaying items that are missing from a room. I created 2 queries, the first getting the items IN the room, and the second being an "unmatched" query that references the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.