Count Function

  • Follow


Hi all, I have a options group on my form with 4 option buttons, there values 
are 1,2,3 & 4 being saved in my table column Currentstatus, I am trying to 
count the various input using the code below, but it does not add up whats in 
my main table, it is sometimes doubling the amounts it finds, any help?b 
Thanks.

Total Entered: Count(*)
Total approved: Sum(IIf([currentstatus],1,0))
Total Reject: Sum(IIf([currentstatus],2,0))
Total NA: Sum(IIf([currentstatus],3,0))
Total TA: Sum(IIf([currentstatus],4,0))

0
Reply Utf 5/25/2010 1:08:01 PM

Your IIf statements are incorrect. Try

Total approved: Sum(IIf([currentstatus]=1,1,0))
Total Reject: Sum(IIf([currentstatus]=2,1,0))
Total NA: Sum(IIf([currentstatus]=3,1,0))
Total TA: Sum(IIf([currentstatus]=4,1,0))


-- 
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"blake7" <blake7@discussions.microsoft.com> wrote in message 
news:6AAF9FEC-B596-40D3-B3F8-9AAD82A97FA8@microsoft.com...
> Hi all, I have a options group on my form with 4 option buttons, there 
> values
> are 1,2,3 & 4 being saved in my table column Currentstatus, I am trying to
> count the various input using the code below, but it does not add up whats 
> in
> my main table, it is sometimes doubling the amounts it finds, any help?b
> Thanks.
>
> Total Entered: Count(*)
> Total approved: Sum(IIf([currentstatus],1,0))
> Total Reject: Sum(IIf([currentstatus],2,0))
> Total NA: Sum(IIf([currentstatus],3,0))
> Total TA: Sum(IIf([currentstatus],4,0))
> 


0
Reply Douglas 5/25/2010 1:16:44 PM


Count needs to include filed name:
Count([yourfieldname])
IIF statements require something defined like:
sum(IIF([yourfieldname]=something,1,0)
If the 1,2,3,4 are text they must be in quotes.
-- 
Milton Purdy
ACCESS 
State of Arkansas


"blake7" wrote:

> Hi all, I have a options group on my form with 4 option buttons, there values 
> are 1,2,3 & 4 being saved in my table column Currentstatus, I am trying to 
> count the various input using the code below, but it does not add up whats in 
> my main table, it is sometimes doubling the amounts it finds, any help?b 
> Thanks.
> 
> Total Entered: Count(*)
> Total approved: Sum(IIf([currentstatus],1,0))
> Total Reject: Sum(IIf([currentstatus],2,0))
> Total NA: Sum(IIf([currentstatus],3,0))
> Total TA: Sum(IIf([currentstatus],4,0))
> 
0
Reply Utf 5/25/2010 1:54:05 PM

Hi Both, thanks for the reply, I tried both suggestions and I get the same 
error message for both "Data type mismatch in criteria expression" ? any 
other suggestions guys. Thanks

"golfinray" wrote:

> Count needs to include filed name:
> Count([yourfieldname])
> IIF statements require something defined like:
> sum(IIF([yourfieldname]=something,1,0)
> If the 1,2,3,4 are text they must be in quotes.
> -- 
> Milton Purdy
> ACCESS 
> State of Arkansas
> 
> 
> "blake7" wrote:
> 
> > Hi all, I have a options group on my form with 4 option buttons, there values 
> > are 1,2,3 & 4 being saved in my table column Currentstatus, I am trying to 
> > count the various input using the code below, but it does not add up whats in 
> > my main table, it is sometimes doubling the amounts it finds, any help?b 
> > Thanks.
> > 
> > Total Entered: Count(*)
> > Total approved: Sum(IIf([currentstatus],1,0))
> > Total Reject: Sum(IIf([currentstatus],2,0))
> > Total NA: Sum(IIf([currentstatus],3,0))
> > Total TA: Sum(IIf([currentstatus],4,0))
> > 
0
Reply Utf 5/25/2010 2:38:03 PM

In a datatype error, you are trying to perform an operation on the wrong 
datatype. Like, trying to add or subtract text instead of numbers or trying 
to type numbers as text. Look at the datatypes in your table. Number, text, 
memo, etc If you need to operate on text, like IIF([yourfield]=1,1,0) then 
put the numbers in quotes like
IIF([yourfield]="1","1","0")
-- 
Milton Purdy
ACCESS 
State of Arkansas


"blake7" wrote:

> Hi Both, thanks for the reply, I tried both suggestions and I get the same 
> error message for both "Data type mismatch in criteria expression" ? any 
> other suggestions guys. Thanks
> 
> "golfinray" wrote:
> 
> > Count needs to include filed name:
> > Count([yourfieldname])
> > IIF statements require something defined like:
> > sum(IIF([yourfieldname]=something,1,0)
> > If the 1,2,3,4 are text they must be in quotes.
> > -- 
> > Milton Purdy
> > ACCESS 
> > State of Arkansas
> > 
> > 
> > "blake7" wrote:
> > 
> > > Hi all, I have a options group on my form with 4 option buttons, there values 
> > > are 1,2,3 & 4 being saved in my table column Currentstatus, I am trying to 
> > > count the various input using the code below, but it does not add up whats in 
> > > my main table, it is sometimes doubling the amounts it finds, any help?b 
> > > Thanks.
> > > 
> > > Total Entered: Count(*)
> > > Total approved: Sum(IIf([currentstatus],1,0))
> > > Total Reject: Sum(IIf([currentstatus],2,0))
> > > Total NA: Sum(IIf([currentstatus],3,0))
> > > Total TA: Sum(IIf([currentstatus],4,0))
> > > 
0
Reply Utf 5/25/2010 2:57:01 PM

Exactly what did you type that caused the error messages to appear?

What is the data type of currentstate: Text, or Number?

-- 
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"blake7" <blake7@discussions.microsoft.com> wrote in message 
news:42FAC61B-5358-45DA-8030-66399F581ED7@microsoft.com...
> Hi Both, thanks for the reply, I tried both suggestions and I get the same
> error message for both "Data type mismatch in criteria expression" ? any
> other suggestions guys. Thanks
>
> "golfinray" wrote:
>
>> Count needs to include filed name:
>> Count([yourfieldname])
>> IIF statements require something defined like:
>> sum(IIF([yourfieldname]=something,1,0)
>> If the 1,2,3,4 are text they must be in quotes.
>> -- 
>> Milton Purdy
>> ACCESS
>> State of Arkansas
>>
>>
>> "blake7" wrote:
>>
>> > Hi all, I have a options group on my form with 4 option buttons, there 
>> > values
>> > are 1,2,3 & 4 being saved in my table column Currentstatus, I am trying 
>> > to
>> > count the various input using the code below, but it does not add up 
>> > whats in
>> > my main table, it is sometimes doubling the amounts it finds, any 
>> > help?b
>> > Thanks.
>> >
>> > Total Entered: Count(*)
>> > Total approved: Sum(IIf([currentstatus],1,0))
>> > Total Reject: Sum(IIf([currentstatus],2,0))
>> > Total NA: Sum(IIf([currentstatus],3,0))
>> > Total TA: Sum(IIf([currentstatus],4,0))
>> > 


0
Reply Douglas 5/25/2010 2:57:54 PM

Since he's trying to use the IIf statement in a Sum statement, the IIf 
statement must return a number, not text.

That means that if [yourfield] is text, you need IIF([yourfield]="1",1,0), 
not IIF([yourfield]="1","1","0").

-- 
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"golfinray" <golfinray@discussions.microsoft.com> wrote in message 
news:113DA324-8390-4ED6-9A4B-E4400A95B65C@microsoft.com...
> In a datatype error, you are trying to perform an operation on the wrong
> datatype. Like, trying to add or subtract text instead of numbers or 
> trying
> to type numbers as text. Look at the datatypes in your table. Number, 
> text,
> memo, etc If you need to operate on text, like IIF([yourfield]=1,1,0) then
> put the numbers in quotes like
> IIF([yourfield]="1","1","0")
> -- 
> Milton Purdy
> ACCESS
> State of Arkansas
>
>
> "blake7" wrote:
>
>> Hi Both, thanks for the reply, I tried both suggestions and I get the 
>> same
>> error message for both "Data type mismatch in criteria expression" ? any
>> other suggestions guys. Thanks
>>
>> "golfinray" wrote:
>>
>> > Count needs to include filed name:
>> > Count([yourfieldname])
>> > IIF statements require something defined like:
>> > sum(IIF([yourfieldname]=something,1,0)
>> > If the 1,2,3,4 are text they must be in quotes.
>> > -- 
>> > Milton Purdy
>> > ACCESS
>> > State of Arkansas
>> >
>> >
>> > "blake7" wrote:
>> >
>> > > Hi all, I have a options group on my form with 4 option buttons, 
>> > > there values
>> > > are 1,2,3 & 4 being saved in my table column Currentstatus, I am 
>> > > trying to
>> > > count the various input using the code below, but it does not add up 
>> > > whats in
>> > > my main table, it is sometimes doubling the amounts it finds, any 
>> > > help?b
>> > > Thanks.
>> > >
>> > > Total Entered: Count(*)
>> > > Total approved: Sum(IIf([currentstatus],1,0))
>> > > Total Reject: Sum(IIf([currentstatus],2,0))
>> > > Total NA: Sum(IIf([currentstatus],3,0))
>> > > Total TA: Sum(IIf([currentstatus],4,0))
>> > > 


0
Reply Douglas 5/25/2010 3:40:53 PM

6 Replies
207 Views

(page loaded in 0.736 seconds)

Similiar Articles:
















7/21/2012 6:33:51 AM


Reply: