iff Fuction question

D

Dennis Villareal

in my query this is what i have in the field.

GC: IIf([GageChange]=Yes,"1")

i would like it to show

if yes show 1 if no show 0

how would i go about that?

thanks
 
D

Dennis Villareal

ok i am getting some kind of error

Syntax error (comma) in query expression
'IIf([GageChange]=Yes,"1",([GageChange]=No,2))'

this info if being pulled from a database where the Data Type is Yes/No

General Tab

Format - Yes/No
Caption -
Default Value - No
Validation Rule -
Validation Text -
Required - No
Indexed - No

Lookup Tab

Display Control - Combo Box
Row Source Type - Value List
Row Source - ";Yes;No"
Bound Column - 1
Column Count - 1
Column Heads - No
Column Widths -
List Rows - 8
List Width - Auto
Limit to List - No




kev100 via AccessMonster.com said:
Are the only 2 possible values for [GageChange] Yes or No ?

If so....the iif statement allows a type of "nested loop/else" function.

It gets a little messy if there are too many possible values....but if all
the syntax is correct...things should work fairly reliably.

Try (assuming only 2 values are possible for GageChange):

IIf([GageChange]=Yes,"1",([GageChange]=No,2))

...note that there are 2 closed parentheses on the end to match the 2 opened
on the left.

If you need a Default value (if GageChange is neither Yes or No).....add the
following:

IIf([GageChange]=Yes,"1",([GageChange]=No,2,default value here))


Give these a try....I'm pretty sure all the syntax is correct.

Thanks


Dennis said:
in my query this is what i have in the field.

GC: IIf([GageChange]=Yes,"1")

i would like it to show

if yes show 1 if no show 0

how would i go about that?

thanks
 
D

Dennis Villareal

still not working with

IIf([GageChange]=Yes,"1",([GageChange]=No,"2","default value here"))
IIf([GageChange]=Yes,"1",([GageChange]=No,"2"))


kev100 via AccessMonster.com said:
Oops...forgot the needed quotes:


IIf([GageChange]=Yes,"1",([GageChange]=No,"2"))

..or..

IIf([GageChange]=Yes,"1",([GageChange]=No,"2","default value here"))


- kev

Are the only 2 possible values for [GageChange] Yes or No ?

If so....the iif statement allows a type of "nested loop/else" function.

It gets a little messy if there are too many possible values....but if all
the syntax is correct...things should work fairly reliably.

Try (assuming only 2 values are possible for GageChange):

IIf([GageChange]=Yes,"1",([GageChange]=No,2))

...note that there are 2 closed parentheses on the end to match the 2 opened
on the left.

If you need a Default value (if GageChange is neither Yes or No).....add the
following:

IIf([GageChange]=Yes,"1",([GageChange]=No,2,default value here))

Give these a try....I'm pretty sure all the syntax is correct.

Thanks
in my query this is what i have in the field.
[quoted text clipped - 7 lines]
 
D

Dennis Villareal

thanks had to change it a little to do what i wanted to but you pointed me to
the right location

IIf([gagechange]=Yes,"1","0")

thanks

Golfinray said:
Or you could do IIF([gagechange]="yes",1," ") for nothing

Dennis Villareal said:
in my query this is what i have in the field.

GC: IIf([GageChange]=Yes,"1")

i would like it to show

if yes show 1 if no show 0

how would i go about that?

thanks
 
J

John W. Vinson

in my query this is what i have in the field.

GC: IIf([GageChange]=Yes,"1")

i would like it to show

if yes show 1 if no show 0

how would i go about that?

thanks

It's much simpler than you're making it.

Assuming GageChange is a Yes/No field...

IIF([GageChange], 1, 0)

The IIF function has three arguments: an expression which is either TRUE or
FALSE (often of the form A = B but it doesn't matter where the true or false
comes from!); the value to return if TRUE; and the value to return if FALSE.

or even

Abs([GageChange])

This works because a Yes/No field is stored as -1 for True/Yes/Checked, 0 for
False/No/Unchecked.
 
R

Ron2006

Whenever I have done a compound iif test it HAS to have the second iif
stated.

Up till now it has been stated as:
IIf([GageChange]=Yes,"1",([GageChange]=No,"2","default value here"))



Should that not rather be:
IIf([GageChange]=Yes,"1",iif([GageChange]=No,"2","default value
here"))


I get a syntax error when trying it the first way.
 
J

John W. Vinson

Whenever I have done a compound iif test it HAS to have the second iif
stated.

Up till now it has been stated as:
IIf([GageChange]=Yes,"1",([GageChange]=No,"2","default value here"))



Should that not rather be:
IIf([GageChange]=Yes,"1",iif([GageChange]=No,"2","default value
here"))


I get a syntax error when trying it the first way.

I didn't suggest the first way. That was your choice.

If GageChange is a yes/no field then you don't need a second condition. It's
either TRUE (yes) or FALSE (no); you don't even need an equality check, since
the first argument of IIF must be either TRUE (return the second argument) or
FALSE (return the third argument). What do you get if you use

IIF([GageChange], 1, 2)
 

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

Similar Threads

IIF statement 1
Null Criteria Problem 4
Query IIF function 3
update query with iff 3
IFF causing a prompt in a query 1
IIf statement in Query 2
IIf statement 4
Subject: Need help on Iff Statement 1

Top