Results 1 to 6 of 6
  1. #1
    kwilbur is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    7

    Using iif for Multiple Conditions

    Hello All,



    I have been trying to figure out why my iif function is only returning the first two options. 1 and 2. I need it to return 5 options. All having ranges. My expression is as follow:

    iff(DaysEmployed<90,"90",DaysEmployed>=90<730,"1", DaysEmployed>=730<1460,"2",
    DaysEmployed>=1460<4745,"3",DaysEmployed>=4745<912 4,"4",DaysEmployed>=9124,"5")

    Maybe Im using the wrong function so I used Switch instead and it still was only reading the first two criteria. I even removed the equals sign but still the same. What am I doing wrong and how could I fix it. I need it to pick from a range and return a number. Is there a way to do this?

    Thanks in advance

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd use Switch, but in either case your range test is wrong. It would have to be

    DaysEmployed>=90 And DaysEmployed <730

    That said, it's much simpler. You rely on the fact that Access will stop testing after the first successful test, so simply test for <90, <730, <1460, etc.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kwilbur is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    7
    After adding the Ands in now Im getting the error for "the expression you entered has a function containing the wrong number of arguments"

    Plan Rate: iif([DaysEmployed]<90,"90",[DaysEmployed]>=90 And [DaysEmployed],730,"1",[DaysEmployed]>=730 And [DaysEmployed]<1460,"2",[DaysEmployed]>=1460 And [DaysEmployed]<4745,"3",[DaysEmployed]>=4745 And [DaysEmployed]<9124,"4",[DaysEmployed]>=9124,"5")

    Even did the switch you suggested and had the same error. Obviously didn't have the same formula. But written out the usual way with and.

  4. #4
    kwilbur is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    7
    ignore the comma in front of 730. i didn't type it in write.

  5. #5
    kwilbur is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2011
    Posts
    7
    scratch that. I found it. Thanks pbaldy without the ands I wouldn't have figured it out. I used your suggestion of using switch. much cleaner and simpler.

    cheers

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. Apparently you didn't like the simplicity of just testing for "less than" progressively larger numbers? For example, you don't have to test for >=90 in the second test. If it was <90, it will never get to the second test.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. iif statement with multiple conditions
    By ragsgold in forum Queries
    Replies: 7
    Last Post: 08-24-2011, 05:38 PM
  2. Macros within Forms/Multiple Conditions
    By screwdrew1 in forum Forms
    Replies: 0
    Last Post: 04-11-2011, 01:28 PM
  3. Replies: 6
    Last Post: 02-13-2011, 06:02 PM
  4. Update Query - Multiple SETS and WHERE conditions
    By jasonbarnes in forum Queries
    Replies: 26
    Last Post: 12-15-2010, 01:08 PM
  5. Expression with multiple conditions
    By techexpressinc in forum Queries
    Replies: 3
    Last Post: 06-19-2009, 08:33 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