Results 1 to 4 of 4
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181

    Query Criteria - Reference Form Combo Box, Return Null

    I have a form with a combo box called cmboESC_LEVEL. The function is for the user to narrow the query to Escalation Level 1, 2, or 3.



    In my data, Escalation Level can only determined by 'not null' cells. The two fields are Triaged_To_Level_2 (if "Yes", the record has been escalated to at least Level 2), and Triaged_To_Level_3 (if "Yes", the record has been escalated to at least Level 3).

    I am trying to get my query to put criteria on Triaged_To_Level_2 and Triaged_To_Level_3. For Triaged_To_Level_2, I am attempting to use the following code, but it is not working:

    Code:
    Switch([Forms]![frmSEARCH]![cmboESC_LEVEL]="Level 1",Null,[Forms]![frmSEARCH]![cmboESC_LEVEL]<>"Level 1","Yes")
    I've tried using nested IIf criteria as well, but the problem seems to be that I cannot return the value of "Null" or "Is Null" as criteria for the field.

    The only other thing I could try would be to change the table fields to Yes/No, rather than the current condition of "Yes"/null. Would that work?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,948
    Why do you need 3 fields for escalation level? Why not one field with 3 value options?
    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
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    well I think you have a couple issues going on; your post title is that this is the query criteria - - I don't feel IF logic can/should go as criteria. It can go as a calculated field - but that's not the title of your post.... So you want your criteria to be a fixed reference. This helps you trouble shoot your query stand alone.

    Put the IF logic in the form as an unbound text box - lets call it "Criteria" ...I would recommend it be:
    =IIF(Forms![frmSEARCH].[cmboESC_LEVEL]="Level 1","","Yes")

    this way you can view the result to be sure the criteria is correct

    then in your query put a simple criteria: Forms![frmSEARCH].[Criteria]

    but I'm not sure your null or "" will return all records if that's what you seek.....try it and see - that is a different topic......

  4. #4
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    Quote Originally Posted by June7 View Post
    Why do you need 3 fields for escalation level? Why not one field with 3 value options?
    Unfortunately that is the way the data has been structured. I am pulling a report from an online database, and using Access to compile reporting statistics.

    Quote Originally Posted by NTC View Post
    well I think you have a couple issues going on; your post title is that this is the query criteria - - I don't feel IF logic can/should go as criteria. It can go as a calculated field - but that's not the title of your post.... So you want your criteria to be a fixed reference. This helps you trouble shoot your query stand alone.

    Put the IF logic in the form as an unbound text box - lets call it "Criteria" ...I would recommend it be:
    =IIF(Forms![frmSEARCH].[cmboESC_LEVEL]="Level 1","","Yes")

    this way you can view the result to be sure the criteria is correct

    then in your query put a simple criteria: Forms![frmSEARCH].[Criteria]

    but I'm not sure your null or "" will return all records if that's what you seek.....try it and see - that is a different topic......
    This also didn't work.



    SOLUTION:

    1. Changed Triaged_to_Level_2 and Triaged_to_Level_3 fields to Yes/No
    2. Changed query criteria to this:

    Code:
    Switch([Forms]![frmSEARCH]![cmboESC_LEVEL]="Level 1",No,[Forms]![frmSEARCH]![cmboESC_LEVEL]<>"Level 1",Yes)
    For Yes/No fields, you cannot put quotes around the Yes and No.

    Thanks for your tips, June and NTC!

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

Similar Threads

  1. Query to return blank or null items.
    By mulefeathers in forum Queries
    Replies: 3
    Last Post: 10-24-2013, 12:45 PM
  2. Union Query to return Null
    By dr4ke in forum Queries
    Replies: 8
    Last Post: 07-06-2012, 12:18 AM
  3. Count query return zero instead of null/blank
    By dhicks19 in forum Queries
    Replies: 1
    Last Post: 04-19-2012, 07:52 AM
  4. Replies: 1
    Last Post: 02-23-2012, 02:27 PM
  5. Query return 0 for null values
    By rachello89 in forum Access
    Replies: 4
    Last Post: 02-23-2012, 08:38 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