Subject Totalising columns & 'Record not located to update' error
Author s.beames@mailbox.gu.edu.au
What is the best way to totalise a column in a grid?

JobsQry is Master to ItemsUsedQry, & "LINE_TOTAL" is a calculated
field. IB3.6Dg

My approach below causes a 'Record not located to update' error when
the ItemsUsedQry gets posted, presumably because I've hit the Eof
within this handler. The SQLMonitor shows it's trying to post most
Detail fields with nulls, after the Master has posted OK.

void __fastcall TJobsForm::ItemsUsedSrcDataChange(TIB_StatementLink
*Sender, TIB_Statement *Statement, TIB_Column *Field)
{
Currency total = 0;
if (Field &&
(Field->FieldName == "QTY" || Field->FieldName == "UNIT_PRICE") &&
Field->IsModified &&
ItemsUsedQry->State == dssEdit)
{
// :7( AnsiString sBookmark = ItemsUsedQry->Bookmark;
for (ItemsUsedQry->First(); !ItemsUsedQry->Eof; ItemsUsedQry->Next
())
{
total += ItemsUsedQry->FieldByName("LINE_TOTAL")->AsCurrency;
}
// :7( ItemsUsedQry->Bookmark = sBookmark;
JobsQry->FieldByName("TOTALCOST")->AsCurrency = total;
JobsQry->Post();
}
}

Any suggestions welcome,
Thank you,
Steve