Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2012
    Posts
    5

    IIF Statement in query

    Hi Everyone,

    I have a column with 3 possible values, exempt, passed and null. I am trying to write a statement within a query that will populate a new column dependent on the values in the original field. The result for the records with "passed" depend on specific dates entered on a form, while the "exempt" and null entries do not and should not rely on the dates entered. This is what I have:



    RFTStatus: (IIf([respiratoryfittest]![status date] Between [Forms]![ahaswitchboard]![From Date] And [Forms]![ahaswitchboard]![thru Date] And [respiratoryfittest]![status]="passed", "complete")) Or (iif([respiratoryfittest]![status]="passed","Complete","Incomplete"))

    I unsuccessfully end up with "-1" for each of the records. What am I doing wrong?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    This is two IIf expressions joined by an OR operator. This evaluates as: This OR That. This further evaluates as True because there is either This or That, hence each record displays -1 (True).

    Trying to follow logic of the expression. Seems that regardless of date, if [status]="passed" should return "Complete".

    Is the date range intended to filter the data and show only those records within the range?
    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
    Join Date
    Oct 2012
    Posts
    5
    Thanks for the quick reply.

    I only want the "passed" records to return a "complete" result if the date falls within the filter range. If the date is outside of the range entered, the result should be "incomplete". The other two values, NULL and Exempt are not dependent on the date range. If there is a record with "exempt", the result should be "complete" and if a record has a null value in the status field, the result should be "incomplete".

    Even though it is still wrong, I see that I made a mistake on the last part (I had "passed" in both status fields). What I meant to enter was:


    RFTStatus: (IIf([respiratoryfittest]![status date] Between [Forms]![ahaswitchboard]![From Date] And [Forms]![ahaswitchboard]![thru Date] And [respiratoryfittest]![status]="passed", "complete")) Or (iif([respiratoryfittest]![status]="exempt","Complete","Incomplete"))

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    And that still gives -1 result on every record (still: 'This' OR 'That').

    Try this:

    RFTStatus: IIf(([respiratoryfittest]![status date] Between [Forms]![ahaswitchboard]![From Date] And [Forms]![ahaswitchboard]![thru Date] And [respiratoryfittest]![status]="passed") OR [respiratoryfittest]![status]="exempt","Complete","Incomplete")
    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.

  5. #5
    Join Date
    Oct 2012
    Posts
    5
    There it is! Many many thanks!!

  6. #6
    Join Date
    Oct 2012
    Posts
    5
    Could I take this one step further to include another condition like below:

    RFTStatus: IIf((([respiratoryfittest]![status date] Between [Forms]![ahaswitchboard]![From Date] And [Forms]![ahaswitchboard]![thru Date] And [respiratoryfittest]![status]="passed") Or [respiratoryfittest]![status]="exempt","Complete") OR [tpeoplesoft matched to tcostcenter]![pay status]="p" or [tpeoplesoft matched to tcostcenter]![pay status]="l","On Leave","incomplete")

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    [tpeoplesoft matched to tcostcenter] is a table/query included in this query by join? Then yes, can include that condtion.

    However, syntax of the new expression is wrong. You almost have another 'This' OR 'That' situation. Does it error when running query?

    An IIf() function has structure:
    IIf(condition, result if true, result if false)

    Nested IIf:
    IIf(condition, result if true, IIf(another condition, result if true, result if false))

    Example of an IIf with multiple OR/AND conditions:
    IIf((condition1 AND (condition2 OR condition3)) OR condition4 OR condition5, result if true, result if false)

    Your latest expression does not fit any of these.
    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.

  8. #8
    Join Date
    Oct 2012
    Posts
    5
    Success! Here's what I came up with. Gracias!

    RFTStatus: IIf(([respiratoryfittest]![status date] Between [Forms]![ahaswitchboard]![From Date] And [Forms]![ahaswitchboard]![thru Date] And [respiratoryfittest]![status]="passed") Or [respiratoryfittest]![status]="exempt","Complete",IIf([tpeoplesoft matched to tcostcenter]![pay status]="p" Or [tpeoplesoft matched to tcostcenter]![pay status]="l","on leave","Incomplete"))

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

Similar Threads

  1. 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
  2. Replies: 3
    Last Post: 07-10-2012, 05:23 AM
  3. Query (if Statement I Think?)
    By Hello World in forum Queries
    Replies: 3
    Last Post: 10-13-2011, 09:25 AM
  4. query iif statement help
    By swat in forum Queries
    Replies: 4
    Last Post: 09-30-2011, 11:48 AM
  5. If then statement in query
    By ronnie4 in forum Queries
    Replies: 1
    Last Post: 01-20-2009, 10:49 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