View Full Version : iif won't return value


Irene
04-26-2000, 02:42 PM
I am trying to do a conditional display in a report. I have simplified it to:

IIf (1,"",[textvar])

that works fine. If I change "1" to "0", I don't get the value of textvar returned, but get "#Error".
Anybody know why?
Thanks

Axis
04-26-2000, 03:00 PM
You seem to be missing the full conditional expression, as in
Iif([Field] = 1,"",[textvar])
or
Iif([Field].Value = 1,"",[textvar])

Irene
04-26-2000, 03:09 PM
Thanks, but that's not the problem.
if I do

IIF (1,"","123") I get the empty string, but if I do
IIF (0,"","123") I get "123"

the problem seems to be only when it should return [textvar].
I'm doing it this way only as a test before I add the real conditional.




[This message has been edited by Irene (edited 04-26-2000).]

Axis
04-26-2000, 04:53 PM
I may be wrong, but I think if you add the real conditional you'll find the expression works. Without an explicit a field or variable, Access is taking whatever variable is open and evaluating it. At least you seem to have gottenr id of your error message.

Irene
04-26-2000, 04:57 PM
Sorry, that doesn't help. I am sure the problem is not in the control part, but in the return of a variable.

Axis
04-26-2000, 07:06 PM
Where are you using this expression? I've tested the same expressions several times, and it always works if there is a condition to evaluate. For example, I have a report with two fields, Score and Placement. Score has a control source of the score field in a table, and Placement is unbound. In the Control Source for Placement I put =Iif([Score]<50,"Under 50","50 or Over"). This expression evaluates the number in the field score and returns one of the 2 choices in the field Placement. It should work for you if you are correctly referring to the field to be evaluated.

Pat Hartman
04-26-2000, 08:06 PM
Irene, Axis is correct. You have not specified a valid condition statement. What do you think "If 0" means - what does "If 1" mean? The test doesn't make any sense. Access is interpreting the condition as - "If 0 is true" or "If 1 is true". As it happens 0 is always false so the false path will always be taken and 1 is always true so the true path will always be taken. Neither test will ever produce a different result so neither could ever be used to toggle a conditional display since that implies that sometimes the condition should return true and sometimes it should return false.