If statement in textbox

B

BZeyger

I have a form with three textboxes:

txtVal1
txtVal2
txtAnswer

I would like to insert a if statement into the text box. However, I do not
know the format of an If statement in a textbox.
I would like txtAnswer to display “Yes†if txtVal1 > txtVal2
it should also display “No†if txtVal1 < txtVal2

This is not what my form looks like, this is just a sample of what I am
looking for. Can someone help me with this formatting? I am trying to avoid
using VB code in the code builder. I would like the code in the text box.

Thanks
 
S

Steve Schapel

BZeyger,

Put this in the Control Source of the txtAnswer textbox...

=Switch([txtVal1]>[txtVal2],"Yes",[txtVal1]<[txtVal2],"No")

If txtVal1 = txtVal2 then txtAnswer will remain blank.

If, in fact, you want the "Yes" or "No" to display in the case of txtVal1 =
txtVal2, then you can use something like this instead...

= IIf(([txtVal1]>[txtVal2],"Yes","No")

Another approach is to enter this for the txtAnswer's Control Source:
=[txtVal1]>[txtVal2]
.... and then set its Format property to:
Yes/No
 
W

Wayne-I-M

= IIf ( [txtVal1] > [txtVal2] , "Yes", "No")

but what if its equal to

3 is more than 2 = yes
2 is more than 3 = no
1 is more than 1 = ???

You can use >= (equal to or more than) or the oposit would be <=

HtH
 

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