Results 1 to 3 of 3
  1. #1
    halnurse is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2016
    Posts
    22

    Nested IIf statement with IsNull

    Hello all - I am having difficulty getting my query to do what I want. I have a table with an item description and then the quantity needed however the quantity could be in one of three columns in the table. I want the query to look at the columns and if the first (Loc1) is null then use the second column (Loc2). If the second column is null, look at the third column (Loc3). I am only having problems if the first two columns are empty and it needs to move to the third column. The query shows a null value here. Can someone point out what I am doing wrong please! Thanks for your time!

    Here is the code I have written:



    Quantity: IIf(Not IsNull([tblTSP_Material_Import]![Loc1]),[tblTSP_Material_Import].[Loc1],IIf(IsNull([tblTSP_Material_Import]![Loc1]),[tblTSP_Material_Import]![Loc2],IIf(IsNull([tblTSP_Material_Import].[Loc1]) And IsNull([tblTSP_Material_Import]![Loc2]),[tblTSP_Material_Import]![Loc3],"")))

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,973
    Quantity: IIf(Not IsNull([Loc1]), [Loc1], IIf(Not IsNull([Loc2]), [Loc2], [Loc3]))

    Or:

    Quantity: Nz(Loc1, Nz(Loc2, Loc3))

    Nz and IsNull are both VBA function calls. For strictly SQL use:

    Quantity: IIf(Not [Loc1] Is Null, [Loc1], IIf(Not [Loc2] Is Null, [Loc2], [Loc3]))
    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
    halnurse is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2016
    Posts
    22
    Thank you, that worked!

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