Results 1 to 12 of 12
  1. #1
    Pat Strauss is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2024
    Posts
    3

    Use of 'not' in specifying a critieria in a query


    I have been using Access for many, many years, but it keeps changing the rules...
    I use to be able to put 'not' in front of a word or phrase that was likely to appear in a field when running a query. The instance could be 'not London' if wanting to display, say, people or companies that didn't have 'London' in their address.
    I don't know what I'm doing differently, but I can't seem to do that now. I can use 'like' but not the opposite request.
    It's not a true / false field, more a filter to display records where a word is not used. If I could get that far, I would be willing to create a new table of the results, but I don't know how to do that from the results of a query.

    Can anyone help?
    Pat

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    I use to be able to put 'not' in front of a word or phrase that was likely to appear in a field when running a query.
    Are you talking about the sql language? In which case which version? Or vba or some other language?

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Cannot see how TBH.
    If you are looking for anywhere in the address you would need *London*, if at the start London*, if at the end *london

    For single values in a field = or <>
    Code:
    SELECT tblDaily.*, tblFoods.FoodName
    FROM tblDaily INNER JOIN tblFoods ON (tblDaily.FoodIDFK = tblFoods.FoodID) AND (tblDaily.FoodIDFK = tblFoods.FoodID)
    WHERE (((tblFoods.FoodName) Not Like "Choco*"));
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Maybe show some examples of what doesn't work (and/or what you get), and what you expect.
    You should be able to use Not LIKE 'text' but you will need wildcards if you have "London, UK". You can't eliminate that with Not "London".
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Pat Strauss is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2024
    Posts
    3
    I presume sql - whatever Access uses by default. This is a simple database, not linked with any other.

  6. #6
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Maybe provide us a spreadsheet or Access table with some records and a few concrete examples of what you want?

    Assume Address(StreetAddress, City, County...)

    SELECT *
    FROM Addresses
    WHERE City <> "London";

    WHERE City Not LIKE '%London%'
    in Murica would omit cities like "New London" and "Londonderry"

  7. #7
    Pat Strauss is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2024
    Posts
    3
    Just tried your suggestion of <>London and it worked!!
    Many thanks.

  8. #8
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    You can also use Not In("London")

  9. #9
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Quote Originally Posted by mike60smart View Post
    You can also use Not In("London")
    You can, but the standard use of NOT IN is with a list of values.

    NOT IN ("London", "Belfast", "Edinburgh")

    and not just a single value.

  10. #10
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,820
    Hi Madpiet
    Very True

  11. #11
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    NOT IN is allegedly a poor choice in big datasets, as it doesn't make very good use of indexes (if at all).
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Have you tried to use the Instr() function like so:

    Instr([YourAddressField],"London")=0 (=not London)

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 28
    Last Post: 05-10-2013, 11:59 AM
  2. Query critieria on Sum of Record
    By ice051505 in forum Queries
    Replies: 2
    Last Post: 03-08-2013, 05:20 PM
  3. Distinct Query Critieria
    By sanywisons232 in forum Queries
    Replies: 3
    Last Post: 01-29-2013, 01:18 PM
  4. Query Critieria using Combo Box Column
    By MintChipMadness in forum Queries
    Replies: 1
    Last Post: 08-23-2012, 02:10 PM
  5. Select as based on other critieria
    By raweber in forum Queries
    Replies: 2
    Last Post: 11-18-2011, 01:20 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums