Belle said:
I have a this syntax located in the control source of a testbox on my form
=IIf(qryCalculations!RecPower<"3",3,IIf(qryCalculations!RecPower<"5",5,IIf(qryCalculations!RecPower<"7.5",7.5,IIf(qryCalculations!RecPower<"9.99",10,IIf(qryCalculations!RecPower<"15","15",IIf(qryCalculations!RecPower<"20.0","20","Error!"))))))
This only works upto returning the value of "10",
Are you sure it's "working?" Because you have enclosed the RecPower
values in quotes, I am assuming that they are actually text, not
numbers. If this is the case, then this expression is not "working" the
way I think you want it to. If RecPower is in fact a text field, the
numeric characters will be evaluated as *text* even though they look
like numbers. For example, if RecPower contains the numeric character
3, this expression returns a 5. If RecPower = "5," this returns "7.5."
Is this really what you want?
how would i use the switch
function and where would I put it?
Can I leave the function in the control source?
Yes, but the SWITCH function won't make any real difference, other than
to make the expression a litle trimmer by cutting down on the nested
IIFs. SWITCH() evaluates multiple expressions in sequence (left to
right) and returns a particular value if a particular expression
evaluates as True. An example would be
SWITCH((qryCalculations!RecPower<"3",3,qryCalculations!RecPower<"5",5,qryCalculations!RecPower<"7.5",7.5,
qryCalculations!RecPower<"9.99",10,qryCalculations!RecPower<"15","15",qryCalculations!RecPower<"20.0",20,
qryCalculations!RecPower>"20.0","Error!")
But this will still have the same logical problems as your original
expression. It looks to me that you are trying to convert text to
values. Assuming you have some reason for keeping the RecPower values
as text & want to convert them to actual numbers in order to do some
kind of math with them in the form, I'd suggest using Val() or Round().
Or have I misunderstood you completely? If so, please clarify.