Count Except

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Count Except

Post by adam »

Hi anyone,

I'm trying to count records that does not include the texts mentioned in the query. The query works fine if I only use one text. If I use two or three texts after a comma it does not work. How could I get this working.

Any help would be appreciated.

Code: Select all

  strSQL = "SELECT COUNT([Products]) FROM tblOrders WHERE [Products] NOT LIKE 'Apple%' 'Orange%'"
    rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic, adCmdText
    ws.Range("E24").CopyFromRecordset rst
    rst.Close  
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Count Except

Post by HansV »

Use

Code: Select all

... WHERE [Products] NOT LIKE 'Apple%' AND [Products] NOT LIKE 'Orange%'"
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Count Except

Post by adam »

Thanks for the help Hans. It worked great.
Best Regards,
Adam