B
BruceM
I have a purchase order main table with a line items child table. They are
related one-to-many. Data entry is by means of a main form with a
continuous subform. It is a standard set-up for such situations.
The user selects the product and the quantity. Product Description, Product
Code, Unit, and Unit Price are displayed based on the Product selection.
ProductID and UnitPrice are saved. The other Product fields are displayed
but not saved. Quantity is entered and saved. The line total is determined
by multiplying Product by UnitPrice.
I tried displaying the purchase order total by means of the expression:
=Sum(Quantity*UnitPrice)
in an unbound text box (txtTotal) in the form footer.
The trouble was that it did not calculate when the Quantity was selected,
but rather when I left the new record. However, attempts to save the record
(and thereby get the correct total in the text box) ran afoul of the
subform's Before Update code, which prevents the user from creating a line
item without a quantity.
All I could come up with was the following in the txtQuantity (the Quantity
text box) After Update event:
Me.txtTotal = DSum("Quantity*Items_UnitPrice", "tblPO_Items", _
"PO_ReqID = " & Me.PO_ReqID & "") + _
(Me.txtUnitPrice * Me.txtQuantity)
In the form's Current event:
Me.txtTotal = DSum("Quantity*Items_UnitPrice", "tblPO_Items", "PO_ReqID = "
& Me.PO_ReqID & "")
This seems unnecessarily awkward, but I cannot seem to find another way to
accomplish this. Am I missing something obvious?
related one-to-many. Data entry is by means of a main form with a
continuous subform. It is a standard set-up for such situations.
The user selects the product and the quantity. Product Description, Product
Code, Unit, and Unit Price are displayed based on the Product selection.
ProductID and UnitPrice are saved. The other Product fields are displayed
but not saved. Quantity is entered and saved. The line total is determined
by multiplying Product by UnitPrice.
I tried displaying the purchase order total by means of the expression:
=Sum(Quantity*UnitPrice)
in an unbound text box (txtTotal) in the form footer.
The trouble was that it did not calculate when the Quantity was selected,
but rather when I left the new record. However, attempts to save the record
(and thereby get the correct total in the text box) ran afoul of the
subform's Before Update code, which prevents the user from creating a line
item without a quantity.
All I could come up with was the following in the txtQuantity (the Quantity
text box) After Update event:
Me.txtTotal = DSum("Quantity*Items_UnitPrice", "tblPO_Items", _
"PO_ReqID = " & Me.PO_ReqID & "") + _
(Me.txtUnitPrice * Me.txtQuantity)
In the form's Current event:
Me.txtTotal = DSum("Quantity*Items_UnitPrice", "tblPO_Items", "PO_ReqID = "
& Me.PO_ReqID & "")
This seems unnecessarily awkward, but I cannot seem to find another way to
accomplish this. Am I missing something obvious?