I'm trying to set up some data validation rules to keep totals in a separate table. I have devised something that works great when I'm browsing the table, but fails when I run a form.
I have fields "parent.Total" and "child.Detail". (parent.Total is the sum of all the child.Detail(s).
(I'm leaving out all the detail, just showing the "meat")
In my row rule for child.dbf I have:
private plChildValid
plChildValid = .t. && to prevent triggering parent valid
select ;
sum(detail) ;
for child.ForeignKey = parent.PrimaryKey ;
into array laTotal
&& Current value hasn't been stored yet.
laTotal(1) = laTotal(1) - OldVal(child.Detail) + child.Detail
select parent
= seek(child.ForeignKey)
replace Total with laTotal(1)
select child
return
In the row rule for parent.dbf I have:
&& skip if updating from the child table
if type('plChildValid')='U' or empty(plChildValid)
if parent.Total<>oldval(parent.Total)
= messagebox( 'Edit Child.dbf to change Detail' )
replace parent.Total with oldval(parent.Total)
endif
endif
return
This works just fine when I browse the table, but during the running of a form with buffering set on the views and tables, it doesn't work. I'm pretty sure that I've narrowed it down to the fact that buffering is set on in parent.dbf (which is off during browsing) so the parent row rule is not triggered until the table is closed (it's tableupdate() has already occured prior to the child's tableupdate()) and at that time type('plChildValid')='U'.
I'm not sure I like the idea of putting a tableupdate(parent) in a valid routine for child. Any other ideas?
TIA
Bill Morris