UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Odd Numbers    
 
   
mtfenn
post 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
Go to the top of the page
 
+
truittb
post 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" )
Go to the top of the page
 
+
mtfenn
post 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
Go to the top of the page
 
+
dannyseager
post 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...
Go to the top of the page
 
+
truittb
post 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<
Go to the top of the page
 
+
mtfenn
post Jan 13 2007, 11:05 PM
Post #6

New Member
Posts: 17



Thanks everyone, That helps a lot. Works like a charm
Go to the top of the page
 
+
truittb
post Jan 14 2007, 12:15 AM
Post #7

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



You are welcome.
Go to the top of the page
 
+
AllyChels
post 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!
Go to the top of the page
 
+
cheekybuddha
post May 1 2014, 08:13 PM
Post #9

UtterAccess VIP
Posts: 6,228
From: Telegraph Hill



Hi and welcome to UA!
welcome2UA.gif
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
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 20th October 2014 - 10:41 PM

Tag cloud: