Unanswered: Urgent please, Always get record before updated ?
Help please, Very urgent.
I use Access XP + ADO with OLEDB for Jet. I have a form with a subform. Both are bound form. Relation is 1 : M. When each record in subform is updated, I write program in Form_AfterUpdate event to sum amount from all records in this subform. I found that I always get amount value but that value is before record is updated. This is part of my program.
Private Sub Form_AfterUpdate()
Dim RS_D as ADODB.Recordset
Dim mSQL as String
Dim wkTotalAmt as Variant ' For keep decimal data type.
mSQL = "select * from OrderDetail where OrderNo = '" & parent!OrderNo & "' "
RS_D.Open mSQL, mCNN, adOpenKeyset, adReadOnly
If RS_D.BOF And RS_D.EOF Then GoTo Form_AfterUpdate_Exit
Do While Not RS_D.EOF
wkTotalAmt = wkTotalAmt + CDec(RS_D!Amt)
I think my code is simple. So, Is it possible that something else may cause this problem ?
Any help so much appreciated.
I have to explain a little more that after update each record I will use the sum value to calculate tax and write tax value to other table also. Question is By your method, Can Access garantee that sum value in main form will be generated before I execute my Form_AfterUpdate event ?
Could you please, if you know, why my code doesn't work ?
Actually your event does work correctly. What may be happening is that the record in the subform is not getting updated ( moving off the record or clicking on the "pencil" in the row selector) before you perform the after update event. Question: Why are you doing the After Update anyways? That event only fires when the form in question gets the focus back ... Focus of a subform won't activate this event.