My Assistant
Custom Search

Odd Numbers 
Jan 13 2007, 02:57 PM Post#1  
Posts: 16 Joined: 10January 07  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,563 Joined: 23June 02 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  
Posts: 16 Joined: 10January 07  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 Joined: 2March 04 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,563 Joined: 23June 02 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  
Posts: 16 Joined: 10January 07  Thanks everyone, That helps a lot. Works like a charm 
May 1 2014, 06:43 PM Post#7  
Posts: 1 Joined: 1May 14  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#8  
UtterAccess VIP Posts: 8,270 Joined: 6December 03 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 
Custom Search

Search Top LoFi  30th June 2016  06:09 PM 