Sums up totals for selected fields.



Sub CalcSums(ByVal hTable As Long, ByVal hRec As Long, ByVal FieldNoArray As Variant)

The handle to the table.

The handle to the record buffer in which sums are to be placed.

The array containing the numbers of the fields that are to be added up.



' Case "CalcSums"

'Calculates the sum of the Amount field for Customers

  CF1.OpenTable hTable, 21

  hRecord = CF1.AllocRec(hTable)


  'Get a key! Assign Keys to array

  KeyArray = Array("Customer No.", "Posting Date", "Currency Code")

  KeyArrayNo = CF1.FieldNoArray(hTable, KeyArray)

  CF1.SetCurrentKey hTable, KeyArrayNo


  ' we want a sum for this field

  KeyArray = Array("Amount")

  KeyArrayNo = CF1.FieldNoArray(hTable, KeyArray)

  CF1.CalcSums hTable, hRecord, KeyArrayNo


  logWr "Calsums gives: " + Str(CF1.GetFieldData(hTable, hRecord, CF1.FieldNo(hTable, "Amount")))


CalcSums adds up totals for specified fields (columns) in a table. The function operates only on those records that meet the conditions specified in any filters that are associated with the table handle.

All of the fields listed in FieldNoArray must be designated in the current key as SumIndexFields. If any of them do not meet this criteria, an exception is raised. To retrieve a list of the SumIndexFields for a given key, call KeySumFields.

A SumIndexField is a special C/SIDE feature that permits speedy access of numeric totals, even in tables that contain many thousands of records.

For more information about SumIndexFields, see the Application Designer's Guide.

© 2009 Microsoft Corporation. All rights reserved.