forcing date in to a field

J

jc

Is there a way I can have the result of a calulation of 2
fields automatically update in to the third field of a
form without making the third field's contol source an
equation.
 
R

Rick Brandt

jc said:
Is there a way I can have the result of a calulation of 2
fields automatically update in to the third field of a
form without making the third field's contol source an
equation.

In the AfterUpdate event of BOTH controls used in the calculation you would
run code to take the result of the calculation and push it into the third
control. Something like...

Me!TextBox3 = Nz(Me!TextBox1,0) * Nz(Me!TextBox2)

It might not be a bad idea to run this again in the BeforeUpdate of the
form itself.

All of the above provided with the caveat that storing data that can be
calculated is *almost never* a good idea. What would be a lot better idea
would be to base the form on a query and have the calculation done in the
query and never store it. If you just use that query in place of your
table, your application would never "know" the difference between that and
a table where the calculation was being stored. Except with the query
there would never be any doubt that the calculation was correct. Something
you cannot guarantee when you store it.
 

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