Odd and even (1 Viewer)

PG2015

Registered User.
Local time
Today, 17:04
Joined
Feb 16, 2015
Messages
21
Hi scratching my head to get an IIF for odds or even in numbers. Ie if its an even number state "EVEN" in column. Obviously if odd state "ODD".:confused:

Any ideas please.

Thanks

PG
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:04
Joined
Aug 30, 2003
Messages
36,132
Check out the Mod operator.
 

PG2015

Registered User.
Local time
Today, 17:04
Joined
Feb 16, 2015
Messages
21
Thanks - afraid I am a bit of a numpty with access and cannot see how to construct MOD in a query string. Any example would be a great help.
 

Minty

AWF VIP
Local time
Today, 17:04
Joined
Jul 26, 2013
Messages
10,372
IIf (YourField Mod 2 ,"Odd", "Even" )
 

PG2015

Registered User.
Local time
Today, 17:04
Joined
Feb 16, 2015
Messages
21
That's got it! Thanks very much for your help.:)
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:04
Joined
Jan 23, 2006
Messages
15,394
I would think
.evenly divisible by 2..if true,..if false
IIf (YourField Mod 2 , "Even","Odd" )
 

sneuberg

AWF VIP
Local time
Today, 09:04
Joined
Oct 17, 2014
Messages
3,506
I would think
.evenly divisible by 2..if true,..if false
IIf (YourField Mod 2 , "Even","Odd" )

Yeah if it were

IIf (YourField Mod 2 = 0 , "Even","Odd" )

Which I think is better since YourField Mod 2 by itself isn't really a boolean expression and just relies on the fact that any non zero values is considered true.
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:04
Joined
Jan 23, 2006
Messages
15,394
Agreed. My issue was with the placement of Odd/Even (should be reversed)
in Minty's post.

Code:
IIf (YourField Mod 2 ,"Odd", "Even" )
 
Last edited:

Minty

AWF VIP
Local time
Today, 17:04
Joined
Jul 26, 2013
Messages
10,372
I actually borrowed it from an excel forum and it seemed to be correct, but as you say it doesn't account for non 0 null values. It's too hot and Monday, that's my excuse...
 

sneuberg

AWF VIP
Local time
Today, 09:04
Joined
Oct 17, 2014
Messages
3,506
Agreed. My issue was with the placement of Odd/Even
in Minty's post.

Code:
IIf (YourField Mod 2 ,"Odd", "Even" )

But that placement is correct with the condition being YourField Mod 2 which is true when the YourNumber is odd. YourField Mod 2 = 0 is true when YourNumber is even.
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:04
Joined
Jan 23, 2006
Messages
15,394
Yes

IIf (YourField Mod 2 = 0 , "Even","Odd" )
 

Users who are viewing this thread

Top Bottom