I need help. How can I display the Total Amount and Net Amount on the main form? I am not able to do it. Please help.

moin555

Member
Local time
Today, 11:21
Joined
Feb 6, 2025
Messages
72
1753780799459.png

BOTH TABEL PURCAHSE AND SALE AMOUNT NOT ADD IN MAIN FORM PLZZ
 

Attachments

add a textbox called say txtSum to the subform footer with =sum(calculation) as the controlsource where calculation is however you are calculating the value (e..g =sum([quantity]*[price])

on the mainform, you reference it with =salesdetails.form.txtSum
 
View attachment 120686
BOTH TABEL PURCAHSE AND SALE AMOUNT NOT ADD IN MAIN FORM PLZZ
You appear to have a Control on the MAIN Form named "DiscountAmount" as well as a Control on the Subform named "Discount".

Do you want to calculate the Discount in the Subform and then display this on the Main Form as well?
 
View attachment 120686
BOTH TABEL PURCAHSE AND SALE AMOUNT NOT ADD IN MAIN FORM PLZZ
You would normally do the calculations in the subform as shown in the attached screenshot.

My apologies the Labels in the subform should be as follows:-
 

Attachments

  • Totals.png
    Totals.png
    22.5 KB · Views: 12
  • Sub.png
    Sub.png
    7 KB · Views: 11
Last edited:
Place a text box in the subform header with these properties
Name: txtAmtTotal
Control Source: =Sum([UnitPrice]*[Quantity]-Nz([Discount],0))

Then change the text box on your main form to:
Control Source: =[SaleDetails].[Form].[txtAmtTotal]
 
Expression must reference subform container name. I always name container different from object it holds, such as ctrDetails, then:

=[ctrDetails].Form.[txtAmtTotal]

or

=[ctrDetails]![txtAmtTotal]
 
Sometimes I 'll stick some code in the OnCurrent() event and simply refresh certain fields.
 
BOTH TABEL PURCAHSE AND SALE AMOUNT NOT ADD IN MAIN FORM PLZZ

Rather than calculating the values for the the computed controls in the form and subform, an alternative would be to return them in the parent form's RecordSource query as follows:

SQL:
SELECT
    *,
    DSUM (
        "(UnitPrice*Quantity)",
        "SaleDetails",
        "SaleID = " & SaleID
    ) AS TotalAmount,
    DSUM (
        "(UnitPrice*Quantity) - Discount",
        "SaleDetails",
        "SaleID = " & SaleID
    ) AS NetAmount,
    NetAmount - ReceivedAmount AS RemainingAmount
FROM
    Sales;

The computed values should not be stored in columns in the tables as this could lead to update anomalies. These columns should be dropped from the table definitions. As noted earlier in this thread you have discount columns in both tables. I've assumed that the Discount column in SaleDetails is the correct one, and that in Sales should be dropped.

The DSum function is used to return the total and net amounts, rather than subqueries, so that the query will return an updatable recordset.
 

Users who are viewing this thread

Back
Top Bottom