Running total on a form
Posted by: fredometro on
Jan 25th, 2004 |
Filed under: MS-Access
It is sometimes needed to show the running total of the records. On a report, there is no problem as this feature in built-in. But on a form, a bit of coding is needed.
Here is a function that will work on any form. The most of it is that you can sort or filter the records, the running total still works because it works with the form’s recordsetclone.
Parameters of the function:
[Amountfield] is the field name we want to totalize
[Keyfield] is the field name of the primary key of your form’s table or query, or simply an unique field.
Public Function RunTotal(AmountField, KeyField)
Dim SumRs As Recordset
Dim frm As Form
Dim RunningValue As Double
Dim IsCancelled As Boolean
Set frm = Forms(AmountField.Parent.Name)
Set SumRs = frm.RecordsetClone
With SumRs
’ Setting first amount
RunningValue = 0
On Error Resume Next
.FindFirst “True”
’ Summing all other
While .Fields(KeyField.Name) <> frm.Controls(KeyField.Name) And Not IsCancelled
RunningValue = RunningValue + .Fields(AmountField.Name)
On Error Resume Next
.FindNext “True”
If Err <> 0 Then IsCancelled = True
On Error GoTo 0
Wend
’ Do the current one
RunningValue = RunningValue + .Fields(AmountField.Name)
End With
Set SumRs = Nothing
RunTotal = RunningValue
End Function


December 12th, 2009 at 7:55 am
Stunning Serena
December 12th, 2009 at 7:56 am
XXX Gay Cum Eaters
December 12th, 2009 at 7:57 am
Milton Twins
December 12th, 2009 at 7:58 am
Gracie Glam
December 12th, 2009 at 7:59 am
Busty Pam
December 12th, 2009 at 8:00 am
Celebrity F
December 12th, 2009 at 8:01 am
Kelly Madison
December 12th, 2009 at 8:02 am
Cock Choking Sluts
December 12th, 2009 at 8:03 am
Sexy Girl Allie
December 12th, 2009 at 8:04 am
Bad Lesbian Girls
December 12th, 2009 at 8:05 am
Lesbo Kittens
December 12th, 2009 at 8:07 am
Naughty Nina Kay
December 12th, 2009 at 8:08 am
Nicole Peters
December 12th, 2009 at 8:09 am
Heidi Heart
December 12th, 2009 at 8:10 am
Courtney Virgin
Add A Comment
You must be logged in to post a comment.