Results 1 to 9 of 9
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    IIF Statement with OR criteria

    Hi,

    I'd like to set up the criteria on one of the fields in a query as an If statement.

    The If statement will reference a form, as such:



    IIF(Form.Control = "March", "January" OR "February" OR "March", "")

    Basically, I want it to notice what month the control has, and to set the criteria to display all months prior and up to that one...

    but this way is not working - how do you set this up?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The IIF() function has 3 parts: IIF(Condition, ValueIfTrue, ValueIfFalse)

    You have to explicitly test each condition. It would look something like:
    Code:
    IIF(ControlName = "March" OR ControlName = "January" OR ControlName ="February" OR ControlName ="March", ValueIfTrue, ValueIfFalse)
    Without knowing what you are trying to accomplish, this might not be the best method. But I hope I have answered your immediate question.

  3. #3
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Correct, I am trying to get it so that the value if true portion has an OR condition... but I don't know if I can do that.

  4. #4
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I think I can get around this issue with numbers, actually.

    Create a new field designating Jan = 1, Feb = 2, etc... etc...

    Then saying something like IIF(Form.Control = 4, Number <= 4, "") or whatever....

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The condition has to evaluate to TRUE or FALSE. The "VALUE IF TRUE" returns a value... or you can have a nested IIF()

    This returns "Q1" or "Q2"
    Code:
    IIF( ControlName = "January" OR ControlName ="February" OR ControlName ="March", "Q1", IIF( ControlName = "April" OR ControlName ="May" OR ControlName ="June", "Q2",  "Unknown"))
    Would you explain what you are trying to do? This doesn't make sense to me.
    value if true portion has an OR condition

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    IIF(Form.Control = 4, Number <= 4, "")
    This will return TRUE if the "Form.Control" has 1, 2, 3 or 4 . Is that what you want?

  7. #7
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    I don't know why, but...

    When I create my query...which has a field called PeriodCalc which contains numbers 1,2,3,4,... etc.



    I set up

    IIF(Form.Control = 4, [PeriodCalc]<=4, 0)

    NOTHING shows up in the query results!


    Why?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    IIF(Form.Control = 4, [PeriodCalc]<=4, 0)
    This should return TRUE (or -1) or Zero.

    What is "Form.Control"?????

    Please post the SQL of your query.

  9. #9
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    I would highly recommend you use the SWITCH function instead.

    http://www.techonthenet.com/access/f...ced/switch.php

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

Similar Threads

  1. If then statement using Yes/No criteria
    By jpiazza in forum Macros
    Replies: 5
    Last Post: 07-12-2014, 11:06 PM
  2. IIf Statement in Query Criteria
    By kyle87 in forum Queries
    Replies: 8
    Last Post: 07-29-2013, 12:31 PM
  3. Help with two criteria in an IIF statement.
    By Orozvik in forum Queries
    Replies: 1
    Last Post: 04-26-2013, 02:58 PM
  4. Iif statement with multiple criteria
    By coach32 in forum Queries
    Replies: 1
    Last Post: 09-07-2011, 01:28 AM
  5. nested if statement with two criteria
    By kendra in forum Queries
    Replies: 5
    Last Post: 06-16-2009, 04:07 PM

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