Building an expression from a query

N

nykevia

I am a self learned Access07 user. I have created a database and need some
experience user knowledge.

In a form, i would like once information is enter in to one text box another
text box automatically updates according to a query.

I worked with someone with a little more knowledge then I, but they were
unsure of how to complete it.

Pls help
 
S

Steve

Put the following code in the AfterUpdate event of the first textbox:

Me!NameOfOtherTextBox.Requery

This assumes you have a calculation in the cntrol source of the other
textbox.

In the alternative your code could calculate the value in the other textbox.
For example:
Me!NameOfOtherTextBox = Me!NameOfFirstTextBox * 3.1416

Steve
(e-mail address removed)
 
N

nykevia via AccessMonster.com

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:

Me!NameOfOtherTextBox.Requery

This assumes you have a calculation in the cntrol source of the other
textbox.

In the alternative your code could calculate the value in the other textbox.
For example:
Me!NameOfOtherTextBox = Me!NameOfFirstTextBox * 3.1416

Steve
(e-mail address removed)
I am a self learned Access07 user. I have created a database and need some
experience user knowledge.
[quoted text clipped - 7 lines]
 
S

Steve

The code goes in the Afterupdate event of the first box. Nothing is needed
in the second box.

Steve


nykevia via AccessMonster.com said:
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:

Me!NameOfOtherTextBox.Requery

This assumes you have a calculation in the cntrol source of the other
textbox.

In the alternative your code could calculate the value in the other
textbox.
For example:
Me!NameOfOtherTextBox = Me!NameOfFirstTextBox * 3.1416

Steve
(e-mail address removed)
I am a self learned Access07 user. I have created a database and need
some
experience user knowledge.
[quoted text clipped - 7 lines]
 
K

KenSheridan via AccessMonster.com

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]
 

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