higher of two values

F

fishqqq

I'm trying to populate a field with the higher value of two other
fields and am not sure how.

field 1 = [buy rate x 15%]
field 2 = [buy rate + 25]
field 3 = higher of the two values

is there a way to automatically populate field 3 with the higher
value?

any ideas are greatly appreciated.

Steve
 
R

Rob Parker

I assume, since you're posting to a forms group, that you're wanting to do
this in textboxes on a form. I also assume that "buy rate" is the name of a
field in your underlying table/query, and that the textbox controls are
named "field 1", field 2" and "field 3". If so, enter the following
expressions in your textboxes:

field 1: =[buy rate]*1.15
field 2: =[buy rate]+25
field 3: =iif([field 1]>[field 2],[field 1],[field 2])

If any of my assumptions about field/textbox names are incorrect, change
these to match the names you have. Note also, that using spaces in
field/control names will force you to enclose those names in square
brackets; not using spaces (recommended practice) would allow you to enter
names without square brackets.

Note also that if you are wanting to do this in a query, you cannot use the
alias names for field 1 and field 2 in the expression for field 2; you must
repeat those expression. So, in a query, for field 3 you would need to
enter:

iif(([buy rate]*1.15)>([buy rate]+25),[buy rate]*1.15,[buy rate]+25)

Finally, I hope you're not intending to store these calculated fields in the
underlying table; they should always be calculated "on-the-fly" in either
unbound textbox controls on a form or in a query, they should never be
stored in the table.

HTH,

Rob
 
F

fishqqq

I assume, since you're posting to a forms group, that you're wanting to do
this in textboxes on a form. I also assume that "buy rate" is the name ofa
field in your underlying table/query, and that the textbox controls are
named "field 1", field 2" and "field 3".  If so, enter the following
expressions in your textboxes:

field 1:    =[buy rate]*1.15
field 2:    =[buy rate]+25
field 3:    =iif([field 1]>[field 2],[field 1],[field 2])

If any of my assumptions about field/textbox names are incorrect, change
these to match the names you have.  Note also, that using spaces in
field/control names will force you to enclose those names in square
brackets; not using spaces (recommended practice) would allow you to enter
names without square brackets.

Note also that if you are wanting to do this in a query, you cannot use the
alias names for field 1 and field 2 in the expression for field 2; you must
repeat those expression.  So, in a query, for field 3 you would need to
enter:

iif(([buy rate]*1.15)>([buy rate]+25),[buy rate]*1.15,[buy rate]+25)

Finally, I hope you're not intending to store these calculated fields in the
underlying table; they should always be calculated "on-the-fly" in either
unbound textbox controls on a form or in a query, they should never be
stored in the table.

HTH,

Rob


I'm trying to populate a field with the higher value of two other
fields and am not sure how.
field 1 = [buy rate x 15%]
field 2 = [buy rate + 25]
field 3 = higher of the two values
is there a way to automatically populate field 3 with the higher
value?
any ideas are greatly appreciated.

thanks, that works perfectly!!!
 

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