Not Like Query

R

ryguy7272

I tried the following in a query, but could not get it to work:
Not Like ("*Top*") Or Not Like ("*Remaining*") Or Not Like ("*Total*") Or
Not Like ("*Quoted*") Or Not Like ("*Solar*")

The items with Top, Remaining, Total, etc., keep showing up in my query
results. The Query is linked to a ComboBox, but that shouldn't matter,
right. Also, I have Group By enabled, but again, as far as I know that
shouldn't interfere with the query results.

What am I doing wrong?

Thanks,
Ryan---
 
V

vanderghast

The engine is right.


Is today NOT sunday, OR NOT monday, OR NOT... ?


Assuming today is Monday, then IT IS NOT SUNDAY, so, we have:

TRUE OR FALSE OR ...

which evaluates to TRUE.



You probably want AND rather than OR.




Vanderghast, Access MVP
 
M

Marshall Barton

ryguy7272 said:
I tried the following in a query, but could not get it to work:
Not Like ("*Top*") Or Not Like ("*Remaining*") Or Not Like ("*Total*") Or
Not Like ("*Quoted*") Or Not Like ("*Solar*")

The items with Top, Remaining, Total, etc., keep showing up in my query
results. The Query is linked to a ComboBox, but that shouldn't matter,
right. Also, I have Group By enabled, but again, as far as I know that
shouldn't interfere with the query results.


That criteria will always be true because if the value is
like one of them, it can not be like another one. Change
the ORs to ANDs.

If you do not have a specific reason for using Group By,
don't use it.
 
J

John W. Vinson

I tried the following in a query, but could not get it to work:
Not Like ("*Top*") Or Not Like ("*Remaining*") Or Not Like ("*Total*") Or
Not Like ("*Quoted*") Or Not Like ("*Solar*")

The items with Top, Remaining, Total, etc., keep showing up in my query
results. The Query is linked to a ComboBox, but that shouldn't matter,
right. Also, I have Group By enabled, but again, as far as I know that
shouldn't interfere with the query results.

What am I doing wrong?

Using the OR boolean operator rather than the correct AND Boolean operator.

OR and AND look like the familiar English language conjunctions but they're
actually operators in algebra, just as + and - are operators in arithmatic.
Their meaning is very strictly defined: X AND Y will be TRUE if both X and Y
are TRUE, and FALSE otherwise. X OR Y will be TRUE if X is true, or if Y is
true, or if both are true; it will be FALSE only if both X and Y are false.

A query criterion is a statement in Boolean algebra. If its value is TRUE the
record is retrieved; if it's FALSE or NULL, the record is excluded.

So... if your record contains SOLAR, you're creating an expression

NOT FALSE OR NOT FALSE OR NOT FALSE OR NOT FALSE OR NOT FALSE OR NOT TRUE

which equals

TRUE OR TRUE OR TRUE OR TRUE OR TRUE OR FALSE

which comes out to TRUE (there's at least one true value).

Use either

Not Like ("*Top*") And Not Like ("*Remaining*") And Not Like ("*Total*") And
Not Like ("*Quoted*") And Not Like ("*Solar*")

or, better, use parentheses:

NOT (Like ("*Top*") Or Like ("*Remaining*") Or Like ("*Total*") Or
Like ("*Quoted*") Or Like ("*Solar*"))

You may want to be careful though - a string containg "stop" or "misquoted" or
"autopilot" will be excluded. The substringing is very literal, it's looking
for a substring, not a word.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top