Results 1 to 7 of 7
  1. #1
    cmorten is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    16

    How to write an Iif statement with AND function and blank value


    Hi All,

    I have been struggling to figure out how to write an Iif statement that includes an AND function. in Layman's term what I want is "IF one field is blank AND another filed contains "DT" then put the words "NOT POSTED" in otherwise put "POSTED"

    This is what I have tried with no luck..

    Code:
    IIF(([RECON] IS NULL) AND ([SOURCE]=”DT”),”NOTPOSTED,”POSTED”)
    In certain iterations of the formula when I did get it to work, it bracketed the words in quotations and then asked me to enter a parameter value for those words which didn't work and resulted in it returning a blank value. I am better in Excel than I am in Access and can follow intermediate formulas and functions but this one has me stumped.

    Any help is appreciated.

  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,892
    You are missing quote mark around "NOTPOSTED".

    Where are you using this expression - in query?

    IS NULL is used in SQL, use IsNull() in textbox or VBA expression.
    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
    cmorten is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    16
    Thanks June7!

    I am in a Make Table query in Design view and I am trying to add a field in that query that will either show "Posted" or "Not Posted". The original expression I was using was....


    Code:
    Transaction Status: IIf([Recon]="YES","POSTED","NOT POSTED")
    This expression worked fine but then we needed make a change in the db.

    If am adding the IsNull would the field formula look like...?

    Code:
    Transaction Status: IIF(ISNULL([RECON]) AND ([SOURCE]=”DT”),”NOTPOSTED”,”POSTED”)

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Not sure if you can have a space in the field alias - Transaction Status

    Code:
    TransactionStatus: IIF(ISNULL(RECON) AND (SOURCE=”DT”),”NOTPOSTED”,”POSTED”)
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    I do advise not to use spaces nor punctuation/special characters in naming convention.
    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.

  6. #6
    cmorten is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    16
    Thanks Moke123 and June 7 your help was appreciated. I believe I have figured it out.

    I needed to first set the expression with a true/false component and then add in a second IIF expression that would determine what to do based on that outcome. In this case the formula looks like this...

    Code:
    IIf(IIf(IsNull([RECON]) And ([SOURCE]='DT'),1,0)=1,"NOT POSTED","POSTED")

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    That complication should not be necessary. Your original expression should produce the same result. The question is why would it not?
    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. Replies: 15
    Last Post: 05-31-2017, 02:10 PM
  2. Replies: 12
    Last Post: 05-14-2017, 10:11 AM
  3. how would i write this if null function?
    By RLehrbass in forum Access
    Replies: 4
    Last Post: 08-03-2015, 02:35 PM
  4. How would I write this IF statement
    By robsworld78 in forum Programming
    Replies: 12
    Last Post: 02-27-2012, 08:01 PM
  5. Replies: 2
    Last Post: 01-08-2012, 12:07 PM

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