Results 1 to 3 of 3
  1. #1
    Bbeards is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Oct 2018
    Posts
    1

    Nested IIf And Or not working

    Hi, I created this field to determine the status of inventory but it appears that the <> is not working properly when I check the values. Do I have some logic wrong or am I missing something? Thank you for your help.


    Inventory Status: IIf([Allotment]=0 And [Stop Sale Flag]="Y","Stop Sale",IIf([Remaining Allotment]>=0 And [Stop Sale Flag]="Y","Cut-off",IIf([Remaining Allotment]>0 And [Stop Sale Flag]<>"Y","Available",IIf([Remaining Allotment]=0 And [Stop Sale Flag]<>"Y","Sold Out","False"))))

    Thanks, Brett

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Where are you doing this calculation (query, table, form, report, etc)?
    Is "Allotment" a numeric field?

    Can you provide some examples of records that are not working that way you like?
    Specifically, what is the value of "Allotment" and "Stop Sale Flag", what is your expected value, and what is it returning?

    By the way you should change this:
    Code:
    Inventory Status: IIf([Allotment]=0 And [Stop Sale Flag]="Y","Stop Sale",IIf([Remaining Allotment]>=0 And [Stop Sale Flag]="Y",...
    to this...
    Code:
    Inventory Status: IIf([Allotment]=0 And [Stop Sale Flag]="Y","Stop Sale",IIf([Remaining Allotment]>0 And [Stop Sale Flag]="Y",...
    Since the first condition is checking for "0" and "Y", there is no reason to check for ">=0" and "Y". It should be ">0" and "Y".
    Anything equal to 0 will get caught in the first check.

    The way you have written it doesn't hurt anything, but it is unnecessary and can be misleading.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Is [Stop Sale Flag] a text type field, not Yes/No type?

    Consider:

    Inventory Status: Nz(IIf([Stop Sale Flag]="Y", Switch([Allotment]=0,"Stop Sale", [Remaining Allotment]>0,"Cut-off"), Switch([Remaining Allotment]>0,"Available", [Remaining Allotment]=0,"Sold Out")), "False")
    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.

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

Similar Threads

  1. Nested iif
    By dref in forum Queries
    Replies: 16
    Last Post: 06-07-2018, 05:27 PM
  2. Nested Loop Not working correctly in Subform
    By canela123 in forum Programming
    Replies: 4
    Last Post: 11-25-2017, 01:48 AM
  3. Nested IIF not working?
    By khughes46 in forum Queries
    Replies: 2
    Last Post: 05-20-2015, 10:35 AM
  4. Replies: 1
    Last Post: 10-29-2012, 11:24 PM
  5. nested functions not working in 2010?
    By Gdm in forum Queries
    Replies: 2
    Last Post: 08-02-2010, 08:02 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