Variable for holding a calculation for a text box

G

Guest

Hello,
I've got a text box on my form header with a calculation in the control
source that adds values from other text boxes on my form.
My problem is that since the calculation is in the control source of my text
box I can not save the sum of the calculation to a field on the forms bound
table.
Is there a way to move this calculation out of the control source and still
have the calculation populate this text box with the sum of the calculation,
so I can choice a field in which to save this calculations sum.

Calculation in the text box control source=
[Tot40yrcomp]+[Totfelt1536]+[Totfelt3036]+ there will be many more other
text boxes added.

It was suggested to me to have a Variable hold the calculation, I’ve been
trying to write a variable but nothing seems to be working, I’ve been trying
to place this variable I made into the after update and before update of the
text box Nothing works I get all 0.00 in the form header text box, Here’s the
code for the variable I made, can some one see if it looks correct.

Dim calcVariable
calcVariable = [Tot25yrcomp] + [Me.feltstot]
mat25yr = calcVariable

I was wondering if I need to say Me.mat25yr = calcVariable

Thanks--Any help will be greatly appreciated.
 
G

Guest

Hi Larry,
How do i copy the information to the bound control? Please explain.

Larry Linson said:
If you are calculating a value that can be recalculated from other fields in
the table/query when it is needed, you should _not_ store it, but
recalculate when needed. If it cannot be, then add another text box to the
form, bound to the field where the information is to be stored, and upon
update of the calculated field, copy the information to the bound control.
Larry Linson
Microsoft Access MVP

patentinv said:
Hello,
I've got a text box on my form header with a calculation in the control
source that adds values from other text boxes on my form.
My problem is that since the calculation is in the control source of my
text
box I can not save the sum of the calculation to a field on the forms
bound
table.
Is there a way to move this calculation out of the control source and
still
have the calculation populate this text box with the sum of the
calculation,
so I can choice a field in which to save this calculations sum.

Calculation in the text box control source=
[Tot40yrcomp]+[Totfelt1536]+[Totfelt3036]+ there will be many more other
text boxes added.

It was suggested to me to have a Variable hold the calculation, I've been
trying to write a variable but nothing seems to be working, I've been
trying
to place this variable I made into the after update and before update of
the
text box Nothing works I get all 0.00 in the form header text box, Here's
the
code for the variable I made, can some one see if it looks correct.

Dim calcVariable
calcVariable = [Tot25yrcomp] + [Me.feltstot]
mat25yr = calcVariable

I was wondering if I need to say Me.mat25yr = calcVariable

Thanks--Any help will be greatly appreciated.
 
L

Larry Linson

If you are calculating a value that can be recalculated from other fields in
the table/query when it is needed, you should _not_ store it, but
recalculate when needed. If it cannot be, then add another text box to the
form, bound to the field where the information is to be stored, and upon
update of the calculated field, copy the information to the bound control.

Larry Linson
Microsoft Access MVP
 
R

Rick Brandt

patentinv said:
Hi Larry,
How do i copy the information to the bound control? Please explain.

In the BeforeUpdate event of the form have code...

Me.BoundControlName = (Expression for value that probably shouldn't be saved)
 

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

Similar Threads


Top