ACC1x: NWIND Orders Form Updates Order Amount Field with ZeroID: Q101090
|
The Order Amount field in the Orders table is incorrectly set to zero.
The Orders.Write Order Amount macro writes the order subtotal,
calculated in the subform footer, to the Order Amount field in the
Orders table before the order subtotal has finished calculating.
The order subtotal is calculated using the Sum() aggregate function,
which runs asynchronously (or, independently) of other actions
on the form. When a field is altered in the subform that affects this
calculation (for example, the Quantity field), the AfterUpdate event
for the subform executes the Orders.Write Order Amount macro. This
macro executes before the new order subtotal can be calculated. As a
result, the macro incorrectly updates the Subtotal field in the table.
The Order Subtotal field in the subform footer cannot be relied on to calculate the correct order subtotal, since it is being calculated independently of other events occurring on the form. Instead, the value should be calculated using the DSum() aggregate function in the Orders.Write Order Amount macro. This result can be written to the Order Amount field in the Orders table.
This change has already been made to the sample database NWIND.MDB that ships with Microsoft Access version 1.1. Following the "Steps to Reproduce Behavior" section is a description of changes that must be made to version 1.0 of the sample database NWIND.MDB to correct this problem. There are additional suggestions to optimize the Orders form for both versions 1.0 and 1.1.
Additional query words: bringing totals from sub to main
Keywords : kbusage FmsSubf
Version : 1.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: March 25, 1999