Feed a form's calculated control value to a table field

J

John Hipskind

I must be missing something basic here.

My table has FieldA, FieldB and FieldC.
FieldC = FieldA+FieldB.
I would like the table's form to calculate FieldC, then
feed it to the table's FieldC.

The form's Control Source for FieldC seems to only give
me the options of either:
1. Binding the control to FieldC, requiring the input of
a user value (without the ability to add FieldA+FieldB),
or
2. Using the unbounded expression "=[FieldA]+[FieldB]",
with no link to the table's FieldC.

Thanks for your help.

John
 
D

Dirk Goldgar

John Hipskind said:
I must be missing something basic here.

My table has FieldA, FieldB and FieldC.
FieldC = FieldA+FieldB.
I would like the table's form to calculate FieldC, then
feed it to the table's FieldC.

The form's Control Source for FieldC seems to only give
me the options of either:
1. Binding the control to FieldC, requiring the input of
a user value (without the ability to add FieldA+FieldB),
or
2. Using the unbounded expression "=[FieldA]+[FieldB]",
with no link to the table's FieldC.

It is possible to do what you want with code, but the reason it isn't a
built-in feature is that it's almost always a bad idea to store data
that can be calculated whenever you want it. Adding two fields, for
example, is *always* faster than reading the stored sum from disk; plus
if you store the sum in FieldC and then later some process changes the
value of FieldA or FieldB, then the stored sum is wrong. If you
calculate the sum when you need it, it cannot be wrong.

You can always get the sum either by using a calculated control (with
controlsource "=[FieldA]+[FieldB]") or by defining a calculated field in
a query (SELECT FieldA, FieldB, FieldA+FieldB AS FieldC FROM MyTable).

There are some circumstances in which you do store the result of a
calculation; for example, when you need to store the result as of this
moment, even if the calculation might give a different result later.
But unless you have such circumstances, you would do much better not to
store the result of a calculation.
 

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