Descending Totals

  • Thread starter Thread starter Graham Jennings
  • Start date Start date
G

Graham Jennings

I am trying to calculate on a report the descending total
of a column ie rather than a DSUM to accumulate value, I
need the opposite. Is there such a thing?
Example
Col.1 wanted DSUM
1 6 1
2 5 3
3 3 6

Any ideas??
 
Graham:

No there isn't such a thing. But that doesn't mean you can't create it
pretty easily. The key thing is that you've got to have the total value at
the start of the first detail record. Here's one method:

1.) Create a variable in the report's declarations section; dimension it
something like

Dim lngCurrentVal as Long (assuming you're dealing with whole numbers)

2.) In the report's OnOpen event, add the following code:

lngCurrentVal = DSum([NameOfField],[NameofReportQuery]) 'Starting Total
Value

(note: I hate dsum, its slow and prone to high use of resources, there's
other ways to get the total, like adding a subquery to your report's query
and having it available as a field rather than counting up twice, but this
is for simplicity and to facilitate example).

3.) Add an unbound text box to your report, call it something like
txtNetValue

4.) In the OnFormat event of the detail section, add code like this:

Me!txtNetValue = lngCurrentValue
lngCurrentValue = lngCurrentValue - Me!FieldWithTargetValue

That would do it; as each row hits, the NetValue field will have the value
of the total minus the previous cumulative row's values.
 
Back
Top