Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DCount for Yes/No Fields 1

Status
Not open for further replies.

bethabernathy

Programmer
Joined
Jul 13, 2001
Messages
254
Location
MX
Hi There:

I am trying to count the number of "Collisions" where the data is "yes" in a report that is based on a query, but I want the total number of "Collisions" in the whole database not those pulled in the query record set. So this is where I am at:

=DCount([Collision]=1,"tblincident")

This is counting all the records for "Collision". What I want to count all the "Collision" in the database where the value is "Yes". I am working on trying to use the

=DCount(Abs([Collision])),"tblincident")

as this "Yes/No" field is giving me some problems, but the above syntax is wrong. Any ideas??

Thanks for everything.

Beth
 
Hi Beth!

Use this syntax: DCount("[Collision]", "tblIncidents",
"[Collision] = 1")

The general syntax for all of the domain aggregate functions is Function(Field, Table or query, Criteria) and I think each needs to be a string.

hth
Jeff Bridgham
 
Actually.. it would be better if you used DSUM to do this. Yes/No field types have values of -1 and 0 respectively. So if you add the values together you'll have the answer for the number of yes's. Then you need to take the absolute value of it to get a positive answer. So here's how the code would go using the field and tablename above:

=Abs(DSum([Collision]),"tblIncident"))

HTH Joe Miller
joe.miller@flotech.net
 
Hi Joe- I tried using this:

=Abs(DSum([Collision]),"tblIncident"))

and I get the message "the expression you entered has a function containing the wrong number of arguments"

I have tried to fool with this and can't seem to get it.

Thanks for your help.

Beth
 
Hi Beth!

Joe's formula should look like this:

=Abs(DSum([Collision],"tblIncident"))

He had one too many close parentheses.

hth
Jeff Bridgham
 
Hi There Jeff: I put your expression into my unbound text box and got a result of "0".

I wonder if there is a way to do it with the Abs going after the DSum?

Then I tried this one:

DCount("[Collision]", "tblIncidents", "[Collision] = 1")

and get the message: "Syntax error - missing operator in expression.

This gets pretty complicated, huh??

Thanks for everything. Beth
 
Hi Beth!

A couple of things I missed:

=DCount("[Collision]", "tblIncidents", "[Collision] = -1")

Put this in your unbound text box and see if it works for you. And you are right, a problem like this shouldn't get so complex! :-)

hth
Jeff Brdigham
 
Hi There Jeff:

I am still getting an error. Any ideas about using the Abs function like this:

=DSum(Abs("[Collision]=-1"),"tblincident")

Of course, this isn't working, but I have had luck with using Abs after the DSum for example in my crazy report this is working great:

=Sum(Abs([Collision]))

but this just sums the values in the query. I am wondering how to use this format with the DSum or DCount?

Also, with this one I get the value of -1:

=DSum("[Collision]","tblincident","[Collision] =-1")

Any other ideas?? Thanks Alot - I really appreciate it.

Beth
 
Hi Again!

One more time! :-) Try:

=Abs(DSum("Collision", "tblIncidents")) or

=DCount("Collision", "tblIncidents", "Collision = -1")

I've tried both of these and they are working well. You might want to check the spelling of the field and the table to make sure they are valid.

hth
Jeff Bridgham
 
Beth,

Jeff's earlier post should work:
Code:
=DCount("[Collision]", "tblIncidents", "[Collision] = -1")
Is the table name tblIncident???

Or, how about a variation of Joe's:
Code:
=Abs(DSum("[Collision]","tblIncident"))
 
Hi Jeff: They both worked perfectly!!!! Thank You!!

Beth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top