Results 1 to 7 of 7
  1. #1
    noaccess is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    3

    Multiple IIf expressions in a form - please help

    Hi,



    I am really new to Microsoft Access and have tried to get a multiple IIf statement to work in a Form but it doesn't. What I want it to do is:

    If Qualifying Car is true and sale price is 20% VAT then *11/66. If qualifying car is true and sale price is 17.5% VAT then *7/47. If qualifying car is false and sale price is 20% then profit *11/66. If qualifying car is false and sale price is 17.5% then profit *7/47. If profit is less than zero then render zero.

    I wrote this...

    =IIf([Qualifying Car]=True And [Selling VAT rate]="20",[Sale Price]*11/66,IIf([Qualifying Car]=True And [Selling VAT rate]="17.5",[Sale Price]*7/47,IIf([Qualifying Car]=False And [Selling VAT rate]="20",[Profit]*11/66,IIf([Qualifying Car]=False And [Selling VAT rate]="17.5",[Profit]*7/47))))

    It doesn't work and nor do I know how to get it to show zero if the Profit is less than zero.

    I have now spent days and days trying to make it happen but I just can't.

    If anyone can help then I would be truly grateful.

    Thanks in advance,

    Sarah

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Have you tried using a User Defined Function (UDF) in a Standard Module for the function? It would be easier to understand and maintain later, especially if you used a Select Case structure. Just pass it both values.

  3. #3
    noaccess is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    3
    Thanks for your advice but unfortunately I don't know what a UDF is. I have since looked on the Help section and seen that it is a macro but I know even less about macros than IIf functions.

    Is there really know way to write it as a multiple IIf that will work?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    have you seen this? https://www.accessforums.net/tutoria...nts-14417.html

    breaking it out, you see this:

    Code:
    IIf([Qualifying Car]=True And [Selling VAT rate]="20",
       ([Sale Price]*11/66), 
          IIf([Qualifying Car]=True And [Selling VAT rate]="17.5",
             ([Sale Price]*7/47),
                IIf([Qualifying Car]=False And [Selling VAT rate]="20",
                   ([Profit]*11/66),
                      IIf([Qualifying Car]=False And [Selling VAT rate]="17.5",
                         ([Profit]*7/47)))))
    so that will tell you right there where the issue is. You have NO false argument in your last nested IIF(). The way you have it written now, it should look like:


    Code:
    IIf([Qualifying Car]=True And [Selling VAT rate]="20",
       ([Sale Price]*11/66), 
          IIf([Qualifying Car]=True And [Selling VAT rate]="17.5",
             ([Sale Price]*7/47),
                IIf([Qualifying Car]=False And [Selling VAT rate]="20",
                   ([Profit]*11/66),
                      IIf([Qualifying Car]=False And [Selling VAT rate]="17.5",
                         ([Profit]*7/47), value if none of above satisfy))))
    But it would be easier to read if you just wrote:

    Code:
    IIf([Qualifying Car]=True
       IIF([Selling VAT rate]="20",
          ([Sale Price]*11/66), 
             IIF([Selling VAT rate]="17.5",
                ([Sale Price]*7/47),
                   [value if qualifying car and vat rate <> above values])),
    IIf([Selling VAT rate]="20",
       ([Profit]*11/66),
          IIf([Selling VAT rate]="17.5",
             ([Profit]*7/47), value if NOT qualifying care and vat rate <> above values)))
    But really what you should do is put this in VBA, under a form's record event of somekind because it would greatly reduce the text you have to look at. See the FAQ for how to do that. Also, you should really wrap multiple math-based operations in (). Simply due to order of ops if it applies, but in your calcs above it does not. It's always easier to read though.

  5. #5
    noaccess is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    3
    Thanks again for all your help...I have done that and now it works fine

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Yay! I don't like to intrude on Allan's post, but I kinda think my FAQ is useful. so of course I had to boast!

    good luck to ya.

  7. #7
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    [QUOTE=ajetrumpet;63521]have you seen this? https://www.accessforums.net/tutoria...nts-14417.html

    breaking it out, you see this:

    Code:
    IIf([Qualifying Car]=True And [Selling VAT rate]="20",
       ([Sale Price]*11/66), 
          IIf([Qualifying Car]=True And [Selling VAT rate]="17.5",
             ([Sale Price]*7/47),
                IIf([Qualifying Car]=False And [Selling VAT rate]="20",
                   ([Profit]*11/66),
                      IIf([Qualifying Car]=False And [Selling VAT rate]="17.5",
                         ([Profit]*7/47)))))
    nice way of presenting IIf() function

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

Similar Threads

  1. Query Expressions
    By Andrea in forum Queries
    Replies: 6
    Last Post: 03-03-2011, 03:57 PM
  2. Multiple Count Ifs and Expressions in Query
    By jonrockwell08 in forum Queries
    Replies: 1
    Last Post: 07-21-2010, 10:44 AM
  3. Nested If Expressions
    By Lynn in forum Forms
    Replies: 5
    Last Post: 03-25-2010, 10:11 AM
  4. Combining Two DCount expressions in one
    By nmodhi in forum Forms
    Replies: 1
    Last Post: 02-26-2010, 10:49 AM
  5. Conditions / Expressions
    By Mark344 in forum Access
    Replies: 1
    Last Post: 02-19-2010, 08:15 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