recalculate text boxes based on manual entries from another(NEED H

G

Guest

I have three text boxes. When a user manually inputs data in one text box, I
want the other two boxes updated automatically.

In other words, everytime Textbox 1 is updated, Textbox 2 and Textbox 3
automatically are updated.



For example,


TextBox 1 Textbox 2 (automatically fills in 100 x .5)
..5 is a rate
User enters 100 50


Textbox 3 (automatically fills in Textbox 1 + Textbox 2)
150

All 3 values are stored in a Table.

tblResults

txtVal1 txtVal2 txtValTotals
100 50 150
 
G

Guest

What you want to do is easy, but you should not do it. Two of the controls
are calculated values and should not be stored in a table. One of the basic
rules of database design it "do not store calculated values in a table". You
do the calculations when the results needs to be presented to a user or used
in another calculations. Storing calculated values wastes time, disc space,
and has a high chance of becoming inaccurate.

First, how it should be done:
Store only the value in Textbox1 in the table.
Make the Control Source properties for 2 and 3:
Textbox2
=Textbox2 * .5
Textbox3
=Textbox1 + Textbox2

If you insist on doing it incorrectly, use the After Update event of TextBox1:

Me.Textbox2 = Me.Textbox1 * .5
Me.Texxtbox3 = Me.Textbox1 + Me.Textbox2
 
A

Al Camp

You don't mention it, but I assume that you are capturing the .5 Rate also? Or, it is
always the same?
For this example let's assume it is constant...
And, rather than your control names, let's use Qty, QtyXRate, and TotalQty.

First, never "save" the results of a calculation that can be "re-derived" in any
subsequent query, form, or report.
Since you've captured the Qty, and you know the Rate, there's no need to save the
QtyXRate or the TotalQty.
Just "display" the calculation results.

Place 2 text controls named QtyXRate and TotalQty on the form with Control Source
of....
= Qty * .5
and
= Qty + (Qty * 5)
respectively.

This will always display the correct calculations, even when Qty is changed.

--
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions
There are 10 types of people in the world.
Those who understand binary, and those who don't.
 
G

Guest

I tried that but the problem I have is ...

The results show up on the screen for textbox 1, textbox 2, and textbox 3
(That's fine) but

when I close the screen and later I want to reopen the screen to see if
those values are still stored.

Textbox 1 shows up because it is a stored value.

Textboxes 2 and 3 reset back to an empty field and I don't know why. I need
advise on how to keep these values visible at any given time.
 

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