Results 1 to 4 of 4
  1. #1
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87

    Nested Count Iif Statement

    I am working on a nested Iif statement that counts vehicles that meet a 3 separate criteria. Below is my Expression in a query:

    CountIncoming: Count(IIf([tbl_OrderDetails]![VIN]=Null,Null,IIf([tbl_OrderDetails]![OnLot]=Yes,Null,IIf([tbl_OrderDetails]![DateSold] Is Not Null, Null,1))))

    The purpose of this expression is to first check to see if the vehicle has a VIN, if it does not then count 0 and stop. If it does have a VIN go to the 2nd Iif statement which checks to see if the On Lot check box is checked. If the check box is checked then count 0 and stop. If the check box is not checked then go to the 3rd Iif statement which checks to see if there is a date in the DateSold field. If there is a date in the DateSold field then count 0. If the vehicle has a VIN, the On Lot Check Box is not checked and there is no date in the Date Sold field then count 1. Otherwise I should get a 0 count.

    Everything is working well except I have one vehicle that was not delivered to us. So it did not have a VIN, was not considered On Lot and did not have a date sold. Because the unit was not assigned a VIN I thought that it should be counted as 0 and then the expression would stop. However, because it does not have a Date Sold it is being counted as 1. So it seems like the only requirement that really matters in the statement is whether the vehicle has a date sold or not.

    Any help would be greatly appreciated. Thank you

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    if you need to nest IIFs then dont bother
    instead either create a lookup query
    or
    write a custom function.

    much easier to read/decode.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Cannot compare anything to Null. Review http://allenbrowne.com/casu-12.html

    Consider:

    CountIncoming: Count(IIf([tbl_OrderDetails]![VIN] Is Null Or [tbl_OrderDetails]![OnLot]=True Or Not [tbl_OrderDetails]![DateSold] Is Null, Null,1))
    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.

  4. #4
    Topflite66 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    87
    Perfect. Thank you for your help June7. Also thank you for the info on Null Errors.

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

Similar Threads

  1. Nested If Then Statement
    By hithere in forum Programming
    Replies: 8
    Last Post: 02-11-2013, 11:43 AM
  2. Nested If/Or Statement
    By kristyspdx in forum Queries
    Replies: 2
    Last Post: 10-15-2012, 04:49 PM
  3. Nested If statement
    By Bellablue in forum Access
    Replies: 7
    Last Post: 10-09-2011, 12:00 PM
  4. Nested IIf Statement
    By traquino98 in forum Queries
    Replies: 5
    Last Post: 06-11-2011, 10:56 AM
  5. Nested Iif statement help
    By Goodge12 in forum Queries
    Replies: 6
    Last Post: 09-21-2010, 11:45 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