I have a form in MS Access 2002 with the following snippet of code behind a command button.
'Requery subform to make sure total is calculated
Me.fsubUpdateShipments.Requery
DoEvents
'Confirm quantities have been entered
If Form_fsubUpdateShipments.txtTotalShipmentQty.Value <= 0 Then
MsgBox "Cannot create shipment, no quantities have been entered", vbCritical
Exit Sub
End If
For months this has been working fine but today a colleague came to me and explained that the error message was showing even when they had entered quantities.
After doing a bit of digging I determined that the .Value <= 0
expression was being evaluated before the textbox in question had finished calculating its value: =Sum([QtyToShip])
. This seems to only occur when the subform has a non-trivial number of records (around 10 or more) and is obviously a serious problem.
Adding a breakpoint on the line containing the If
statement allows the code to run correctly but I obviously cannot use this method permanently.
Is there some way I can force the code to pause until the subform controls have finished recalculating their values?