Results 1 to 4 of 4
  1. #1
    jlgray0127 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    193

    Query Criteria Like or is null

    Hello.


    I am struggling to find the fix for this. I found it once upon a time, but am not asking the correct question.

    I have an unbound, main form with several unbound combo boxes which use other tables for sources and a subform whose source is a query.

    Once I make a selection I want to filter the results in the sub query.

    For years, I had done this using:

    Field
    Recovery Group

    Criteria
    Like "*" & [Forms]![MTP_Wk_Main_Snap]![RecovGPComb] & "*" Or Is Null

    This almost works great. If I do not make a selection, the query only looks at the combo boxes with criteria selected.
    If I select a value, it will provide the records that match.

    THE PROBLEM:
    Not all records have a value in this field. So, if I select Recovery group 1, I get Recovery group 1 and any records which are null.
    I can not seem to put my finger on how to rewrite this to show me the records with a matching or almost matching value ad not show me the null fields Thoughts on what I cam missing here?

    If I select a value in the combo box, I want only the records that match. If I leave the combo box as null, I want all records.

    Hopefully this is clear and simple enough. I am sure the answer will be blatantly obvious if someone would be so kind as to share their thoughts. Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Criteria is in query design? I don't normally use dynamic parameterized queries. I use VBA to build filter criteria and apply to form or report. Review: http://allenbrowne.com/ser-62.html

    Otherwise, try:

    Nz([Recovery Group], "") LIKE "*" & Nz([Forms]![MTP_Wk_Main_Snap]![RecovGPComb],"") & "*"

    Is Recovery Group a number type field? How many groups are there? LIKE operator does not work properly with number values.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    What about

    Like "*" & [Forms]![MTP_Wk_Main_Snap]![RecovGPComb] & "*" Or [Forms]![MTP_Wk_Main_Snap]![RecovGPComb] Is Null

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    To explain the answers so as to not repeat that sort of thinking in the future, each part of this expression needs to be able to stand on its own:
    Like "*" & [Forms]![MTP_Wk_Main_Snap]![RecovGPComb] & "*" Or Is Null

    so Like "*" & [Forms]![MTP_Wk_Main_Snap]![RecovGPComb] & "*"
    can stand alone but

    Or Is Null
    makes no sense in terms of code.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 5
    Last Post: 07-18-2024, 09:19 AM
  2. Like vs Not Like in Criteria
    By RandyH in forum Queries
    Replies: 4
    Last Post: 12-19-2020, 08:16 PM
  3. Replies: 1
    Last Post: 03-16-2017, 12:29 PM
  4. Replies: 1
    Last Post: 02-23-2012, 02:27 PM
  5. Passing criteria "NULL" or "IS NOT NULL" to a query
    By SgtSaunders69 in forum Forms
    Replies: 1
    Last Post: 12-24-2011, 02:22 AM

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