Get Sum Amount from SubForm

K

katz

Hello,
I have posted this problem before but no solution, I will try to explain it
better because it's very important to me, please help.

I have a Mainform (Invoice) with a Subform with details. In the subform I
have a
control name 'Amount ' and in the Form footer I have a control TotAmt that
Sums the Amount from all the records in the Subform (the total amount of the
invoice).

I also have a textbox TotInvoiceAmt displayed on the main form. e.g.
TotInvoiceAmt =[Invoice Detail].[Form]![TotAmt], to display the total amount
of the invoice on the Mainform.

I also have a button called PayButton on the Invoice Mainform that is using
the amount (the total amount of the invoice) from the txtbox TotInvoiceAmt
for other processing.

As I enter the detail records the TotInvoiceAmt gets updated, as I go to the
next
record (line). But when I am entering details before going to the next line,
the
TotInvoiceAmt is not updated yet (because it's not saved yet).

The problem is, many times I can press the PayButton before going to the
next line, and the TotInvoiceAmt doesn't include the last line from the
details so I don't have the total amount of the invoice (only if I press
twice the PayButton).

In Short, when I press the PayButton I need the Total amount of the Invoice.

somebody told me to add DoEvents on the Click event,
somebody told me to try Me.[NameOfYourSubfomControl].Form.Dirty = False
but it doesn't work.

Is there an other solution? Please Let me know.
Thanks again
Happy New Year

Abe
 
B

Baz

When you leave the subform to click the button on the main form the detail
record is automatically saved, so that isn't the problem. Sounds like a
synchronisation thing to me: the code in the button's Click event is running
BEFORE Access has updated TotInvoiceAmt as a result of the record save.

Instead of referring to TotInvoiceAmt in your code, have you tried referring
directly to the control in the subform's footer i.e. Invoice
Detail].[Form]![TotAmt]? Or have you tried TotInvoiceAmt.Requery?
 
K

katz

Hi, Thanks for response, This is very funny (not funny) I just realized that
when I go thru the code step by step, its good. I see the correct calculated
amounts in the variables, and then I display the results on the screen i.e..
me.TotPaidAmt = varAmt. But without debugging it doesn't work.
thanks

Baz said:
When you leave the subform to click the button on the main form the detail
record is automatically saved, so that isn't the problem. Sounds like a
synchronisation thing to me: the code in the button's Click event is
running BEFORE Access has updated TotInvoiceAmt as a result of the record
save.

Instead of referring to TotInvoiceAmt in your code, have you tried
referring directly to the control in the subform's footer i.e. Invoice
Detail].[Form]![TotAmt]? Or have you tried TotInvoiceAmt.Requery?

katz said:
Hello,
I have posted this problem before but no solution, I will try to explain
it better because it's very important to me, please help.

I have a Mainform (Invoice) with a Subform with details. In the subform I
have a
control name 'Amount ' and in the Form footer I have a control TotAmt
that Sums the Amount from all the records in the Subform (the total
amount of the invoice).

I also have a textbox TotInvoiceAmt displayed on the main form. e.g.
TotInvoiceAmt =[Invoice Detail].[Form]![TotAmt], to display the total
amount of the invoice on the Mainform.

I also have a button called PayButton on the Invoice Mainform that is
using the amount (the total amount of the invoice) from the txtbox
TotInvoiceAmt for other processing.

As I enter the detail records the TotInvoiceAmt gets updated, as I go to
the next
record (line). But when I am entering details before going to the next
line, the
TotInvoiceAmt is not updated yet (because it's not saved yet).

The problem is, many times I can press the PayButton before going to the
next line, and the TotInvoiceAmt doesn't include the last line from the
details so I don't have the total amount of the invoice (only if I press
twice the PayButton).

In Short, when I press the PayButton I need the Total amount of the
Invoice.

somebody told me to add DoEvents on the Click event,
somebody told me to try Me.[NameOfYourSubfomControl].Form.Dirty = False
but it doesn't work.

Is there an other solution? Please Let me know.
Thanks again
Happy New Year

Abe
 
J

Jeanette Cunningham

Katz,
I agree with Baz and it fits with the thing working in debug mode but not in
real life.
Here's a suggestion - I wonder if you are trying to save the Tot amount paid
to a table?
If you are, you might want to consider that many people would not save the
Tot amount paid, but just calculate it (whenever it is needed) in a query
for display on a form or report.
This could be much easier for you to manage.

Jeanette Cunningham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top