But be aware that you should only assign a value to the second text box if
the user can then legitimately change the value. This will normally mean the
second text box is bound to a field in the underlying table, and the value
being assigned to it is a default which can then be either left as it is or
changed by the user.
If the value in the first text box always determines what the value in the
second text box should be and cannot be changed, then the second box should
not be bound to a field in the underlying table as that would introduce
redundancy, which leaves the table open to inconsistent data. Instead the
second text box should be an unbound control with a ControlSource property
which computes the value from that in the first text box. Lets assume as an
example that the form is based on a table of products and the first text box
is a net price, bound to a NetPrice field in the table, and you want to add
10 percent to it to show a gross price in the second text box, then the
ControlSource for the second text box would be:
=[NetPrice]*1.1
No code is needed at all for this. As soon as the value is entered into the
first text box the second will show the computed value.
That's a rather unrealistic example, however, as no-one would realistically
have a fixed margin of 10 percent for every item. It is more likely in that
sort of situation that the gross price would be based on the value of the net
price plus a margin in another field in the underlying table, so the
ControlSource for the GrossPrice control would be:
=[NetPrice]*(1+[Margin])
where the Margin field has a value of 0.1 for 10 percent, 0.25 for 25 percent
and so on.
It can also be done in a query underlying the form by including a computed
column in the query. With the above example you'd enter the following in the
'field' row of a blank column in the query design grid:
GrossPrice:[NetPrice]*(1+[Margin])
You can then simply set the ControlSource of a text box on the form to:
[GrossPrice]
If you also set its Locked property to True (Yes) and its Enabled property to
False (No) the user will be prevented from even trying to change its value.
If this doesn't point you in the right direction with regard to your own
scenario post back with a more detailed description of what you are
attempting to do.
Ken Sheridan
Stafford, England
by entering this code in the first box, it will tell the second box what to
do?
do i not need anything in the second box?
Put the following code in the AfterUpdate event of the first textbox:
[quoted text clipped - 15 lines]