Results 1 to 5 of 5
  1. #1
    sparkes84 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    2

    IIf, And, Or combination in Access Query

    Dear all,

    This is my first post.

    I am working within an Access query and cannot get the following code to work. Can anybody help me? It is saying that if the Project site actual recruitment end date is null and the Project_Site_Status is neither Open or Suspended, then put Yes, else put No.

    Code:
    IIf([Project site actual recruitment end date] Is Null And ([Project_Site_Status]<>"Open" Or [Project_Site_Status]<>"Suspended"), "Yes", "No")
    Many thanks,
    sparkes84

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    When you start nesting IIFs it can give weird results. (OR should be AND here)
    Is there no way you can just use these settings in criteria of the query rather than in an IIF?

    in the query:
    [Project_Site_Status]
    not "Open" and not "Suspended"


    [Project site actual recruitment end date]
    Is Null

    MyField: YES

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    a little bit of code on its own isn't much help. What does 'cannot get the following code to work' mean? you get an error? - if so what is the error description? or it returns the wrong value? or something else?

    Suggest post the entire sql to your query together with a clearer explanation of what the problem is

    Only thing I can see at the moment is you have an inconsistency in your field naming convention, sometimes you have spaces, sometimes underscores, perhaps they should all be one or the other

  4. #4
    sparkes84 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    2
    Thanks Ranman256. I changed the OR to And, making it work. I copied only a small part of a nested IIF statement so cannot make use of the criteria option in this case.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    I changed the OR to And

    ([Project_Site_Status]<>"Open"AND [Project_Site_Status]<>"Suspended"),
    am I missing something - how can Project_Site_Status be 'Open' and 'Suspended' at the same time?

    answered my own question not =, it's <>

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

Similar Threads

  1. Replies: 3
    Last Post: 04-12-2016, 07:15 AM
  2. Replies: 11
    Last Post: 01-21-2014, 10:51 AM
  3. Replies: 3
    Last Post: 08-25-2010, 07:04 AM
  4. Replies: 1
    Last Post: 05-21-2010, 02:22 PM
  5. Replies: 1
    Last Post: 09-09-2009, 04:42 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