KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Generating the Sum for records in a subform
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: May 21, 1999

This tech tip covers the easiest way of generating the Sum of the records in a subform. Assume that a database had the tables listed below and the Invoices input form has a subform for Invoice_Items. In this input form, Invoice_Total would contain a sum of Item_Price for all the records in the subform.

The sum needs to be updated when a value is changed in Item_Price and when a record is deleted in the subform. To update the sum when a record is changed in Item_Price, the following code needs to be executed:

To update the sum for when a record is deleted, execute the following code in the button that deletes the record:

Notice the 2nd code example subtracts Item_Price from the sum. This is because this code will get executed before the record is deleted.