Results 1 to 9 of 9
  1. #1
    pj33558 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    18

    Arrow IIF or Switch or ??

    I know this is probably easy/peezy for everyone on here but after lots of research, I still can't get my calc to fly right.

    I have a lengthy accounting list of subaccounts.

    Currently, I have a table with percentages based upon type of food to eat, and how much gets paid to supplier.

    So, for instance, if the animal is a horse and the supplier sends EQS, then the percentage paid is 5% x 12 months up front; if the animal is a zebra, and the supplier sends EQS, then the percentage is 5% but only 1 month, for every other kind it is EQT x 1 month.

    My current IIF statement reads:

    PCTERND: IIF([subDE]="15",[amount]*[animal-mff]*12,IIf([subDE]="16",[ amount]*[eqs], iif([subDE]=(), [ amount]*[ser])))



    The piece in blue ink is NOT working. I need the calc to grab everything not 15 and not 16, and perform the calc.

    I have tried: Switch([subDE]="15",[amount]*[animal-mff]*12,[subDE]="16",[ amount]*[eqs],[subDE] not in (“15”,”16”),[ amount]*[ser])

    With SWITCH, I get #error; with the IIF I get $0 amounts for anything that is not 15 or 16 (otherwise, it works perfectly).

    The name on the side of number field, is not used nor identified in the database, it is used by accounting. I simply added it for reference.

    15 horse
    16 zebra
    17 donkey
    25 lion
    26 tiger
    35 bear
    57 fish
    80 dog
    81 hyena
    82 wolf
    83 coyote

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I believe IIF parses left to right so just leave off the last IIF and assume it is not 15 or 16. BTW, is the first fields numeric or text? You are treating it as text. No quotes needed for a numeric value.

  3. #3
    pj33558 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    18
    Great point @ "text" or "numeric" - the pull is direct via ODBC from G/L and I believe it comes in as text, hence my "" around the numbers... but I will check.

    2nd - thank you - will try eliminating last IIF - ty.

  4. #4
    pj33558 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    18
    So, the "catch all" by eliminating last IIF, worked like it should.

    However, now, it does not recognize "80". Should there be an "or" before that?

    So: IIF([subDE]="15",[amount]*[animal-mff]*12,OR IIf([subDE]="16",[ amount]*[eqs], [ amount]*[ser])

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    NO. You did not say anything about 80 before. If you want to test for it then add another IIF.

  6. #6
    pj33558 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    18
    Sorry, my bad. 80 is actual number in the field, not my hypothetical.

    The formula is NOT recognizing the "16" nor performing the calculation.

    I get the correct amount for 15 and for everything BUT "16" ... the highlighted piece is not being calculated at all.

    So it reads: IIF([subDE]="15",[amount]*[animal-mff]*12,IIf([subDE]="16",[ amount]*[eqs], [ amount]*[ser])

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You don't have enough arguments but aside from that, have you tried eliminating the quotes to see if they are really numbers rather than text?

  8. #8
    pj33558 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    18
    Figured it out.

    My field name was wrong: [ account] does not = [amount]

    Thank you!

  9. #9
    pj33558 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    18
    Quote Originally Posted by RuralGuy View Post
    have you tried eliminating the quotes to see if they are really numbers rather than text?
    The ODBC link crashes when I try to open that table in design view to see what the properties are. I believe at one point, I tried without the "" and I got errors.

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

Similar Threads

  1. Switch Statement
    By comfygringo in forum Queries
    Replies: 4
    Last Post: 09-04-2013, 03:07 PM
  2. Switch to Access 2010
    By NISMOJim in forum Access
    Replies: 1
    Last Post: 11-17-2012, 09:45 PM
  3. Switch board only allows 4 items
    By jaymin in forum Forms
    Replies: 1
    Last Post: 06-25-2012, 04:40 AM
  4. VBA to switch from one access database to another
    By DRoss902 in forum Programming
    Replies: 5
    Last Post: 02-13-2012, 03:52 PM
  5. Switch and Tables
    By UtilityRyan in forum Database Design
    Replies: 0
    Last Post: 06-12-2007, 03:49 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