Results 1 to 12 of 12
  1. #1
    newbie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    34

    Question Iff Statement Meeting 2 Conditions

    I am trying to create a count function in the report footer. My IIf statements where only 1 piece of criteria needs to be met are working great. I am using:



    =Count(IIf([ControlName]="Yes",0))

    I need to create an IIf statement that will count only if 2 piecec of criteria are met. I have tried a few things but I keep getting an error when I run the report that the expression is either typed incorrectly or is too complex. I have listed a few of the options I have tried below. Is there a way to fenagle one of these so that I can recieve a count of records meeting both criteria?

    =Count(IIf([Control 1]="Yes" & [Control 2]="Yes",0))
    =Count(IIf([Control 1] & [Control 2]="Yes",0))
    =Count(IIf([Control 1]="Yes", Count(IIF([Control 2]="Yes",0)),0) this one returned a cannot have aggregate function error.
    =IIf([Control 1]="Yes",Count(IIf([Control 2]="Yes",0)),0)

    Thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try:
    =Count(IIf([Control 1]="Yes" AND [Control 2]="Yes",1,0))

  3. #3
    newbie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    34
    No, I get the same message that either my expression is typed incorreclty or it is too complex.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If you leave off the Count() does it work?

  5. #5
    newbie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    34
    That eliminated the error message, but just returned a result of 0 when there are 6 records matching both criteria.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are [Control 1] and [Control 2] both Text fields?

  7. #7
    newbie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    34
    Yes, both control 1 and control two are Yes/No text fields. I have to pull the count from the report itself and not the underlying query, because the query has parameters. The report itself pulls back the exact filtered info I want counted, just can't seem to get there.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    TextFields and Yes/No fields are not the same. I believe the Yes/No is actually just an Integer forld with either 0 (NO) or -1 (YES) as a value. Try this:
    =IIf([Control 1] = Yes AND [Control 2] = Yes,1,0)
    ...and see what happens. Note - No quotes. You could also try
    =IIf([Control 1] AND [Control 2] ,1,0)
    ...and you should get the same results.

  9. #9
    newbie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    34
    Still no luck. I tried with the numeric values as well. It is returning an all record count.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I was just trying to find the right criteria first without the count. When I do what you are doing in a report I usually put an invisible control in the detail section with an IIF() to give me a 1 or 0. Then I just Sum() in the footer.

  11. #11
    newbie is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2009
    Posts
    34
    OMG!!!! I finally got it.

    I created an unbound text in my report footer and set the control source to:
    =Sum(IIf([control 1]="Yes" And [control 2]=Yes,1,0))

    I feel like I just ran a marathon!! One issue down, several more to go.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success.

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

Similar Threads

  1. how to use IF then statement
    By ronnie4 in forum Access
    Replies: 1
    Last Post: 03-17-2009, 11:32 PM
  2. I need help writing a query statement
    By dking in forum Queries
    Replies: 1
    Last Post: 02-25-2009, 09:43 AM
  3. If then statement in query
    By ronnie4 in forum Queries
    Replies: 1
    Last Post: 01-20-2009, 10:49 AM
  4. IF Statement with Minutes
    By sal_gxer in forum Queries
    Replies: 0
    Last Post: 02-12-2007, 08:39 AM
  5. multiple iif statement NEED HELP PLZ
    By scott munkirs in forum Reports
    Replies: 1
    Last Post: 09-27-2006, 05:21 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