Results 1 to 4 of 4
  1. #1
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63

    Create a new field with iif statment in a query

    Hello,



    Can someone please help me. I want to create a new field in my query call "Conforming" and another field called "Non-Conforming".

    For "Conforming" I would like to have an iif statement like so (forgive my pitiful excuse for pseudocode I'm not very good with VBA)

    iif Field 1 = 1, 3 or 4 And
    Field 2 = 1, 3 or 4 And
    Field 3 = 1, 3 or 4 And
    Field 4 = 1, 3 or 4 And
    etc.....
    Then
    Conforming = 1


    For the "Non-Conforming" field I would like:

    iif Field 1 = 2 OR
    Field 2 = 2 OR
    Field 3 = 2 OR
    Field 4 = 2 OR
    etc....
    Then
    Non-Conforming = 1

    There may be a way to just include the 2nd outcome into the first code as an else statement:

    iif Field 1 = 1, 3 or 4 And
    Field 2 = 1, 3 or 4 And
    Field 3 = 1, 3 or 4 And
    Field 4 = 1, 3 or 4 And
    etc.....
    Then
    Conforming = 1
    Else
    Non-Conforming = 1


    But I'm not sure, like I said I suck at VBA. The may even be another way to do this without code. I have know Idea.

    Can someone help me out?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You're right there. Building on your example:

    iif(Field 1 = 2 OR Field 2 = 2 OR Field 3 = 2 OR Field 4 = 2, "Non Conforming", Conforming")

    If your fields actually have spaces, they would have to be bracketed of course.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    Awesome! Where would I add this? In the criteria?

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Where would I add this? In the criteria?
    You would put it in a calculated field in your query, i.e.
    Code:
    STATUS: iif(Field 1 = 2 OR Field 2 = 2 OR Field 3 = 2 OR Field 4 = 2, "Non Conforming", Conforming")
    See: http://office.microsoft.com/en-us/ac...aspx?section=3

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

Similar Threads

  1. if statment
    By ismailkhannasar in forum Access
    Replies: 3
    Last Post: 01-31-2013, 06:48 AM
  2. if statment or case statment?
    By whojstall11 in forum Forms
    Replies: 4
    Last Post: 07-09-2012, 01:44 PM
  3. Placed in a State
    By lrobbo314 in forum Access
    Replies: 3
    Last Post: 04-07-2012, 11:26 AM
  4. Like statment
    By brew in forum Programming
    Replies: 2
    Last Post: 12-01-2011, 03:23 AM
  5. Verify state field
    By pwmichaelsr in forum Access
    Replies: 5
    Last Post: 08-16-2010, 12:49 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