PC Review


Reply
Thread Tools Rate Thread

How do I count records using an iif statement?

 
 
Kelvin Beaton
Guest
Posts: n/a
 
      30th Mar 2007
I want to get a count of the number of records where the field [TaskName]
equals "Face to Face" and the field [Message] is blank
I've tried this in a text box on the report:
=IIf([Message] Is Null,(Sum(Abs([TaskName]="Face to Face"))),"no")

I know this part works:
(Sum(Abs([TaskName]="Face to Face")

This statement in a query:
=IIf([Message] Is Null,(Sum(Abs([TaskName]="Face to Face"))),"no")
Gives me this error message:
You tried to execute a query that does not include the specified expression
'TaskID' as part of an aggregate function.

This is what the query looks like:
SELECT tbl_TasksDue.*, IIf([Message] Is Null,(Sum(Abs([TaskName]="Face to
Face"))),"") AS test
FROM tbl_TasksDue
WHERE (((tbl_TasksDue.CaseStatus)="1" Or (tbl_TasksDue.CaseStatus)="2") AND
((tbl_TasksDue.CloseDate) Is Null));

"TaskID" is the primary key of the table "tbl_TasksDue"

Can someone point me in the right direction?

Thanks

Kelvin


 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
Guest
Posts: n/a
 
      30th Mar 2007
Kelvin:

Firstly don't use the fact that Boolean values are implemented in Access as
0 or -1. Its not good practice. The head of a software company of my
acquaintance once described it as being "unduly chummy with the
implementation". Instead Sum the return value of an expression which
returns 1 or 0.

You then need to use a Boolean AND operation to determine if both conditions
are TRUE, the value of TaskName and Message being NULL, so the complete
expression would be:

SUM(IIF(TaskName = "Face to face" AND Message IS NULL,1,0))

To use this as a column in the query you'd need to use a subquery and
restrict in on the same columns as the outer query:

SELECT tbl_TasksDue.*,
(SELECT SUM(IIF(TaskName = "Face to face" AND Message IS NULL,1,0))
FROM tbl_TasksDue
WHERE CaseStatus IN("1","2")
AND CloseDate IS NULL)
AS TaskCount
FROM tbl_TasksDue
WHERE CaseStatus IN("1","2")
AND CloseDate IS NULL;

In a computed control in a report footer or group footer (for a subtotal)
you'd use a similar expression:

=Sum(IIf([TaskName] = "Face to face" And IsNull([Message]),1,0))

Ken Sheridan
Stafford, England

"Kelvin Beaton" wrote:

> I want to get a count of the number of records where the field [TaskName]
> equals "Face to Face" and the field [Message] is blank
> I've tried this in a text box on the report:
> =IIf([Message] Is Null,(Sum(Abs([TaskName]="Face to Face"))),"no")
>
> I know this part works:
> (Sum(Abs([TaskName]="Face to Face")
>
> This statement in a query:
> =IIf([Message] Is Null,(Sum(Abs([TaskName]="Face to Face"))),"no")
> Gives me this error message:
> You tried to execute a query that does not include the specified expression
> 'TaskID' as part of an aggregate function.
>
> This is what the query looks like:
> SELECT tbl_TasksDue.*, IIf([Message] Is Null,(Sum(Abs([TaskName]="Face to
> Face"))),"") AS test
> FROM tbl_TasksDue
> WHERE (((tbl_TasksDue.CaseStatus)="1" Or (tbl_TasksDue.CaseStatus)="2") AND
> ((tbl_TasksDue.CloseDate) Is Null));
>
> "TaskID" is the primary key of the table "tbl_TasksDue"
>
> Can someone point me in the right direction?
>
> Thanks
>
> Kelvin
>
>
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: How to count records using count(*) in a chart report FL Microsoft Access Reports 3 1st Dec 2009 11:31 PM
enter a count function to count records? Kimberly Microsoft Access Queries 11 14th May 2008 07:39 AM
How do I count records using an iif statement? Kelvin Beaton Microsoft Access Queries 1 30th Mar 2007 06:16 PM
How do I count records using an iif statement? Kelvin Beaton Microsoft Access Reports 1 30th Mar 2007 06:16 PM
IIF Statement to Count Specific Records =?Utf-8?B?VGlubGV5UGFya0lMR2Fs?= Microsoft Access Reports 5 19th May 2006 08:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:43 AM.