Results 1 to 7 of 7
  1. #1
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125

    Using the IIF function, the last option is not functional

    In my form footer, I have three four controls
    • Gross Amount (Named: "TxtGrossAmount")
    • GDiscount (Gross Discount in value e.g $30)
    • TDiscount (Discount in percentage form. E.g. 4%)
    • Net Payable (Named "TxtNetPayable")


    On the control of "NetPayable" I have attached the following IIF function:

    =IIf([GDiscount] And [TDiscount] Is Not Null,([TxtGrossAmount]-[GDiscount])*(1-[TDiscount]),IIf([GDiscount] Is Null,[TxtGrossAmount]*(1-[TDiscount]),IIf([TDiscount] Is Null,[TxtGrossAmount]-[GDiscount],[TxtGrossAmount])))


    1. The function should test if the controls "GDiscount" and "TDiscount" have a value in them, If yes, it subtracts GrossDiscount from GrossAmount and to the difference, it applies the rate in the control "TDiscount" then returns the final answer. (This works good)
    2. Secondly, it test if GDiscount is Null, and If yes, it applies the rate in "TDiscount" and returns the difference. (This works well too)
    3. Thirdly, it verifies if "TDiscount" is Null, and If yes, It looks for the difference between "GrossAmount" and "GDiscount" and returns that difference. (this works well)
    4. Finally, in the absence of TDiscount and GDiscount, it should return the Gross Amount. (This is were the problem lies)


    I dont know why the last condition is not respected.

  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,930
    =IIf(Not IsNull([GDiscount] And Not IsNull([TDiscount]), ([TxtGrossAmount]-[GDiscount])*(1-[TDiscount]), IIf(IsNull([GDiscount]), [TxtGrossAmount]*(1-[TDiscount]), IIf(IsNull([TDiscount]), [TxtGrossAmount]-[GDiscount],[TxtGrossAmount])))

    Or maybe just:

    =([TxtGrossAmount]-Nz([GDiscount],0))*(1-Nz([TDiscount],0))
    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
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    Thanks June7
    The first one returns an error msg "The expression you entered has a function containing a wrong number of arguments"
    but the second one solves my problem.

    Just that I don't yet understand how the second function works to produce accurate results, yet so short to write.
    If there is a link i can use to learn more about it i will be very grateful.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I must have misplaced paren in there somewhere, which I now see is a missing paren: =IIf(Not IsNull([GDiscount])

    Search Access and VBA Help for Nz function.

    Also review http://allenbrowne.com/casu-12.html
    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.

  5. #5
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    It still returns a null value for the last condition.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is that for the long version? I don't know why it would unless TxtGrossAmount is null.

    But you have solution with the Nz() version?
    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.

  7. #7
    Demerit's Avatar
    Demerit is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    125
    Thanks I have the solution with the Nz(), just thought i should let you know.

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

Similar Threads

  1. Access 2010 Macro not Functional in 2007
    By dargo72 in forum Macros
    Replies: 5
    Last Post: 10-24-2013, 08:54 AM
  2. Replies: 3
    Last Post: 11-19-2012, 03:07 PM
  3. Replies: 7
    Last Post: 10-03-2011, 02:46 PM
  4. Replies: 2
    Last Post: 07-21-2011, 08:57 AM
  5. open small popup form by press functional key
    By alex_raju in forum Access
    Replies: 0
    Last Post: 07-13-2011, 09:20 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