Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

IIF question in an Access 2007 Query?

I am running a query which is listed below that is looking for a -1 in each check field then if it has a -1 then I want it to return the value for the text field it represents. If it has a value of 0 or null then return nothing at all. It is not returning any values and I could use some help on the formatting of the IIF statement. Something is just not right.

SELECT Survey_Feed.Session_ID, Survey_Feed.Question2_check, Survey_Feed.Question5_check, Survey_Feed.Question9_check, Survey_Feed.Comment_check

FROM Survey_Feed

WHERE (((Survey_Feed.Question2_check)=IIf([question2_check]='-1','[question2]','')) or ((Survey_Feed.Question5_check)=IIf([question5_check]='-1','[question5]','')) AND ((Survey_Feed.Question9_check)=IIf([question9_check]='-1','[question9]','')) AND ((Survey_Feed.Comment_check)=IIf([Comment_check]='-1','[Disposition_Comments]','')) AND ((Survey_Feed.Submit_Time)=Date()-10));

Update:

Here is the extended Where information:

WHERE (((Survey_Feed.Question2_check)=IIf([question2_check]='-1','[question2]','Null')) AND ((Survey_Feed.Question5_check)=IIf([question5_check]='-1','[question5]','')) AND ((Survey_Feed.Question9_check)=IIf([question9_check]='-1','[question9]','')) AND ((Survey_Feed.Comment_check)=IIf([Comment_check]='-1','[Disposition_Comments]','')) AND ((Survey_Feed.Submit_Time)>#5/2/2010# And (Survey_Feed.Submit_Time) Between (Date()-7) And Date()));

Update 2:

=IIf([Comment_check]='-1','[Disposition_Comments]','')

1 Answer

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    We can't see your iif statements, but they would take the form of

    WHERE (Survey_Feed.Question2_check = (iif(question1check = -1, textfield1,"")) or ...

    It tests whether the check field is -1. If it is it returns the value of the text field to the WHERE clause, testing that text field against the text in Survey_Feed.Question2_check. If the check field isn't -1, it returns blank text (which is tested against Survey_Feed.Question2_check in the WHERE clause).

    I think your logic is incorrect here. You want to return something that can be compared to a check field, which is normally true or false (a boolean field) or -1/0 (using a numeric field to hold a pseudo "true/false" value. So you'd want your iif() to return -1 or 0, or true or false - whichever your check field uses. You can't have the WHERE clause determine the value of the return in a field in the SELECT clause, it only determines whether that record will be returned. The field values will be the ones in the record.

Still have questions? Get your answers by asking now.