Results 1 to 7 of 7
  1. #1
    frustratedwithaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Posts
    35

    iif statement in access query

    Hello All,

    I am attempting to create an IIF statement in an access query.

    What would my statement look like if trying to do the following with 4 fields?

    field1, field2, field3, field4

    - field4 should be a calculation based on field1, field2 and field3

    If field 1 equals 0, then field 4 should = field2 + field3


    If field 1 equals 1, then field 4 should = null

    Any ideas?

    Thanks!

  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,929
    What have you tried and why doesn't it work - error message, wrong results, nothing happens? Can field1 have values other than 0 or 1?

    Is field4 actually in the table? Is this a Calculated type field?

    IIf([Field1]=1, Null, [field2] + [field3])
    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
    frustratedwithaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Posts
    35
    field 1 is either a 0 or 1.

    results have shown null in cells, or "error".

    field 4 is supposed to be a calculated field (field2 + field3, depending on if field1 is a 0 or 1... if it's a 0, then I want the values of field2 and 3 added together for the sum in field 4)

  4. #4
    frustratedwithaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Posts
    35
    this is what I am trying:

    field4: IIF([field1]=1,NULL, [field2] +[field3]

    which keeps giving me "error"

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This is the second thread today dealing with expression in Calculated field that works in 2010 but not in 2013. The IIf() works for me.

    Field1 is a number type?

    Try the expression in query instead of table.
    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
    istari88 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Kentucky, USA
    Posts
    13
    Is the problem solved by closing the IIF parenthesis?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Good catch, istari.

    Missing paren at end of 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.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2014, 04:22 PM
  2. switch statement in a access query
    By Dominic in forum Access
    Replies: 1
    Last Post: 03-27-2013, 11:32 PM
  3. Replies: 1
    Last Post: 10-15-2012, 02:41 PM
  4. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  5. problem with IF THEN statement in access 2003 query
    By sfgiantsdude in forum Access
    Replies: 4
    Last Post: 01-05-2012, 04:23 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