Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help counting odd/even numbers in access query 3

Status
Not open for further replies.

Fibee

Programmer
Jul 26, 2002
39
GB
Hi there
Does anyone know of a formula or a way of counting either only odd or only even numbers in a range of numbers? I have 3 fields as below:

FROMHOUSE TOHOUSE ODD/EVEN
52 58 E
84 92 E
33 37 O
41 49 O

How do I get access to only count the even numbers or only count the odd numbers in the ranges?
Any thoughts would be greatly appreciated!!
Thank
Fi
 
Fibee: Good question. In VB you can use the MOD function to see if a number is odd or even, for example

MOD(57,2) <> 0 but MOD(44,2) = 0

..giving the decimal remainder as 0 or some value.

I'm not sure if vba in Access supports this function.
Great question; hopefully someone with a little more experience can shed some light on this.

You could write a Public Function much like Jeff did above in the Thread &quot;Trim Leading Zeros&quot; (very nice) but the code would be much cleaner if MOD was operational.

We'll see what develops.
 
yes, access has a mod function

the syntax is expr1 Mod expr2

as in

[tt]select count(*) as oddcount
from houses
where tohouse mod 2 = 1[/tt]


rudy
 
Thanks very much both - I will give it ago!
Fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top