>There may be a totally simple and superior way to do this, but I am currently befuddled as to how to achieve the following:
>
>The scenario:
>
>1. Parent/Child form - Invoice/WorkOrder
>2. Grid on form - line-items related to Invoice/WorkOrder #. The RecordSource for the grid is an alias.
>3. Invoice total field = total of calculated qty*price in lineitems grid.
>4. I wish to keep form buffered to allow rollback (don't we all love to be able to change our minds?)
>5. Would like to be able to update invoice total on InteractiveChange event of qty or price controls.
>
>So, to achieve above, I try to store the value in the source table by changing the bound control, and do a requery, as follows;
>
>SELECT sum(qnty*price) as invototal FROM involine WHERE docnum = ;
>ThisForm.Pageframe1.Page1.txtDocnum.value INTO CURSOR _xtotal
>replace invoice.amount with _xtotal.invototal
>ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt.Value = _xtotal.invototal
>ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt.Refresh()
>
>
>This yields sporadic and unintelligible results, which is understandable in a buffered situation.
>
>So next, I go looking for properties of the grid that might useful. There, I find ColumnCount, but no RowCount. I think that if I had a RowCount property I could do a quick FOR... NEXT loop or something.
>
>As I type this a glimmer enters my mind about calculating the rowcount by doing a COUNT on the ALIAS against records matching my relational expression, maybe building it into my GRID class.
>
>Is there something already in the language that does most of this, or do I have to keep playing the Mad Inventor?
Andrew,
If you do a scan..endscan on recordsource (alias of child) you could get your buffered data. However you don't need and wouldn't want to move pointer in most cases. SQL operates with data on disk - tableupdated set but that's enough. Scenario goes like this :
-When parent changes data is likely to be tableupdated (or reverted) and thus have SQL selectable data for a particular parentID. SQL sum there and update textbox.value (invoice total replacement should go to tableupdate point, no need to replace per item).
SELECT sum(qnty*price) FROM involine WHERE docnum = ;
ThisForm.Pageframe1.Page1.txtDocnum.value INTO array arrtotal
lnTotal = iif(_Tally=0,0,arrTotal)
ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt.Value = lnTotal
-Now lnTotal is only affected by changes in qnty and price fields, right ? On gotfocus of both fields you could save the current value to textbox tag :
this.tag = transform(this.value)
-On lostfocus update .txtInvoAmt.Value with new value (subtract old, add new) :
with ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt
.Value = .Value + (this.value - val(this.tag))*myalias.price
endwith
This way pointer doesn't move and in case of a lot of childs no performance degradations occur (such as a human would do manually - never sum per change only update with difference:).
Cetin