How to create a calculating control on a form

  • Thread starter Thread starter Marilyn
  • Start date Start date
M

Marilyn

I have a form with a field called CurrentInvoiceAmt. I would like to enter a
dollar amount into this field and have it automatically transferred to a
field called TotalInvoiced. Each time a new invoice is generated, I would
type the dollar amount in that CurrentInvoiceAmt field (which clears the
previous value) and the new value would be automatically added to the
existing value in the TotalInvoiced field. I would rather not have several
Invoice fields and sum them in a separate control. Thank you so much for your
help.

Marilyn
 
Marilyn,
I think this is what you want...
Use the AfterUpdate event of CurrentInvoiceAmt...
TotalInvoiced = TotalInvoiced + CurrentInvoiceAmt
 
Al,

I tried your suggestion by going to the AfterUpdateEvent property of the
CurrentInvoiceAmt control on the form and typed in the expression you listed.
Nothing happened when I entered data into the CurrentInvoiceAmt field. The
TotalInvoiced field remained empty. Do I have to write a macro to generate
the action. Thank you.
 
Marylyn,
I think what you're saying is that you typed the expression right into
the box beside the AfterUpdate property. That's not where it would go...
With your cursor in the AfterUpdate property box, click the little down
arrow on the right, and select [Event Procedure]
Now, click the 3 dot box on the right, and that will take you into the
module for the form... between these 2 lines of code...

Private Sub CurrentInvoiceAmt_AfterUpdate()

End Sub

This where the code goes that you want to execute on the AfterUpdate
event of CurrentInvoiceAmt.
Now, place the code I gave you between the lines...

Private Sub CurrentInvoiceAmt_AfterUpdate()
TotalInvoiced = TotalInvoiced + CurrentInvoiceAmt
End Sub

Exit the module and return to your form design, run the form, enter a
CurrentInvoiceAmt, and test.
That should do it...
 
Al,
I entered the code as you suggested and it worked. Thank you so very much for
your help.
Marilyn

Al said:
Marylyn,
I think what you're saying is that you typed the expression right into
the box beside the AfterUpdate property. That's not where it would go...
With your cursor in the AfterUpdate property box, click the little down
arrow on the right, and select [Event Procedure]
Now, click the 3 dot box on the right, and that will take you into the
module for the form... between these 2 lines of code...

Private Sub CurrentInvoiceAmt_AfterUpdate()

End Sub

This where the code goes that you want to execute on the AfterUpdate
event of CurrentInvoiceAmt.
Now, place the code I gave you between the lines...

Private Sub CurrentInvoiceAmt_AfterUpdate()
TotalInvoiced = TotalInvoiced + CurrentInvoiceAmt
End Sub

Exit the module and return to your form design, run the form, enter a
CurrentInvoiceAmt, and test.
That should do it...
[quoted text clipped - 31 lines]
 
Back
Top