MS Access Query OR Criteria

I have been struggling with this one. I don't understand why it does not work. In my query criteria if I use OR it never works.

If I use:
<> "US Postal Service" Or "Shipping" Or "Joes Inc."

It always returns "Shipping"  "Joes Inc." with the other results.

What am I doing wrong????
LVL 1
Dustin StanleyEntrepreneurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you need to provide the field name as well, and i guess you mean this:

yourfield <> "US Postal Service" and yourfield <> "Shipping" Or  yourfield <> "Joes Inc."

Open in new window


or use in clause, like:

yourfield not in ( "US Postal Service" , "Shipping" , "Joes Inc." )

Open in new window

0
PatHartmanCommented:
Ryan is correct in his assessment of your syntax error however.  Due to the logic error, the expression will return everything rather than what you think it should return because only one of the OR conditions needs to be true and since yourfield cannot possibly be two different values, one of the conditions will ALWAYS be true.

The correct expression would use  ANDs as the relational operator.

yourfield <> "US Postal Service" and yourfield <> "Shipping" And  yourfield <> "Joes Inc."

Ryan's suggestion to use IN() is more concise and better once you have more than two values.

SQL uses the Boolean logic we know and love from Algebra I.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
The correct expression would use  ANDs as the relational operator.

yourfield <> "US Postal Service" and yourfield <> "Shipping" And  yourfield <> "Joes Inc."
yea, there was a typo for second condition in which it should be as "and" instead of "or".

thanks Pat for correction anyway.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dustin StanleyEntrepreneurAuthor Commented:
Perfect! I did not think about putting [YourField] in there. Thanks for the help.
0
PatHartmanCommented:
Use the QBE to build queries if you don't know the syntax.  Then if you absolutely must use the SQL embedded in VBA rather than the saved querydef, switch to SQL view and copy the string into your code.
0
Dustin StanleyEntrepreneurAuthor Commented:
Sounds good! Thank you for the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.