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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DCount With 'OR' Returning All Records in Table! 2

Status
Not open for further replies.

b1kerch1ck

Programmer
Nov 22, 2001
29
0
0
US
I have a DCount problem that is driving me crazy. I have searched the posts and can't find anyone with the same problem.

I am building a query based on a table called tblRegItem. I want to count items based on itemNumber.

If I enter:
DCount("[itemNumber]","tblRegItem","[itemNumber] = 1")
...the query returns a count of 1, which is correct.

If I enter:
DCount("[itemNumber]","tblRegItem","[itemNumber] = 18")
...the query returns a count of 6, which is also correct.

If I try to do a DCount 'this or that', ie:
DCount("[itemNumber]","tblRegItem",("[itemNumber] = 1" Or "[itemNumber] = 18"))
...the query returns a count of 75, the number of records in the entire table.

I have tried variations on syntax, ie adding/removing parentheses, to no effect.
I'm pretty sure I've used this same DCount query successfully in the recent past, without problem.

Can anyone tell me what I am doing wrong?!?!?!

Thanks.
 
Pay attention to the quotes:

[tt] DCount("[itemNumber]","tblRegItem",("[itemNumber] = 1 Or [itemNumber] = 18"))[/tt]

Roy-Vidar
 
One way:
DCount("itemNumber", "tblRegItem", "itemNumber=1 Or itemNumber=18")
Another way:
DCount("itemNumber", "tblRegItem", "itemNumber In (1, 18)")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Wow, I really appreciate this after a v stressful day!
My parentheses were wrong, and the IN function worked a treat!
Thank you so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top