5

I would like to filter all the rows that are:

field like "*AA*" and field not like "*BB*"

But this is returning everything instead of showing all the rows that contains AA and doesn't contain BB.

well now it works like expected, just restarted ms access...

Sorry for my typo... :s updated

Aldwoni
  • 1,168
  • 10
  • 24
Totty.js
  • 15,563
  • 31
  • 103
  • 175

6 Answers6

12

Try this:

field like "*AA*" and field not like "*BB*"
June7
  • 19,874
  • 8
  • 24
  • 34
Paddy
  • 33,309
  • 15
  • 79
  • 114
1

What I found out is that MS Access will reject --Not Like "BB*"-- if not enclosed in PARENTHESES, unlike --Like "BB*"-- which is ok without parentheses.

I tested these on MS Access 2010 and are all valid:

  1. Like "BB"

  2. (Like "BB")

  3. (Not Like "BB")

Ponytell
  • 73
  • 1
  • 7
0

Simply restate the target field & condition;

where (field like "*AA*" and field not like "*BB*")
Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

what's the problem with:

field like "*AA*" and field not like "*BB*"

it should be working.

Could you post some example of your data?

Diego
  • 34,802
  • 21
  • 91
  • 134
0

Not sure if this is still extant but I'm guessing you need something like

((field Like "AA*") AND (field Not Like "BB*"))
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Roy
  • 1
0

If you're doing it in VBA (and not in a query) then: where field like "AA" and field not like "BB" then would not work.

You'd have to use: where field like "AA" and field like "BB" = false then

Serge
  • 1