My Assistant
Odd Numbers


Jan 13 2007, 02:57 PM
Post
#1


New Member Posts: 17 
I'm relatively new to access and have what I hope is a basic question.
Can I get access to return numbers based on whether they are odd or even. What I want is to make a query that basically looks like this IIf ([Field]=Odd, yes, no) For Iif (Odd([field]), yes, no) (thats how I do it in excel) Any thoughts? Thanks a bunch 


Jan 13 2007, 03:15 PM
Post
#2


Retired Moderator Posts: 13,562 From: Texas (Is there anywhere else?) 
Welcome to Utter Access.
Use the Mod operator. IIf(8 Mod 2,"Odd", "Even" ) 


Jan 13 2007, 03:29 PM
Post
#3


New Member Posts: 17 
sorry I'm not familiar with this.
There do I select the field to determine if the selected field is odd or even? what is the 8 and 2? thanks 


Jan 13 2007, 04:01 PM
Post
#4


UtterAccess VIP Posts: 13,031 From: Leicester, UK 
Using truittb's method would be
If([FieldName] Mod 2,"Odd", "Even" ) Alternativly you could use If(Int([FieldName]/2)<>([FieldName]/2),"Odd","Even") You can use this expression in many places... form conrols, as a new column in a query, controls in reports... 


Jan 13 2007, 04:20 PM
Post
#5


Retired Moderator Posts: 13,562 From: Texas (Is there anywhere else?) 
Thanks Danny
o explain further, Mod is used to divide two numbers and return only the remainder. So 8 Mod 2 is dividing 8 by 2 and there is no remainer so the result is 0. An odd number will always have a remainder 7 Mod 2 will be 1 From Access VBA Help< 


Jan 13 2007, 11:05 PM
Post
#6


New Member Posts: 17 
Thanks everyone, That helps a lot. Works like a charm



Jan 14 2007, 12:15 AM
Post
#7


Retired Moderator Posts: 13,562 From: Texas (Is there anywhere else?) 
You are welcome.



May 1 2014, 06:43 PM
Post
#8


New Member Posts: 1 
Hi Everybody,
This is my first post so I hope all is well! Just want to ask why did the IIF statement return a false value on this IIf(8 Mod 2,"Odd", "Even" ) when there is no logic operator? I'm sorry for the question but I really don't get it and by the way I'm a rookie..... hehehehe! Thanks in advance! 


May 1 2014, 08:13 PM
Post
#9


UtterAccess VIP Posts: 6,229 From: Telegraph Hill 
Hi and welcome to UA!
This takes advantage of the convention in programming that 0 = FALSE and [any number other than 0, though usually 1 or 1] = TRUE. Odd numbers will have a remainder of 1  so this is evaluated as TRUE So, the expression essentially says: IIf(TRUE,"Odd", "Even" ) Even numbers will have a remainder of 0  so this is evaluated as FALSE So, the expression essentially says: IIf(FALSE,"Odd", "Even" ) hth, d 


Search · Go to Top · LoFi Version  Time is now: 25th October 2014  05:49 PM 