Counting number of true entries of a logical variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have several fields in a d/b that are "true/false" type. I am trying to
display the count of the true entries in these fields. When I try to use the
count function in a query I get the total number of records in the d/b. I've
tried to use the criterion that the variable is true. Can anyone help? I
would think this would be an easy thing to do.
 
try

Sum(Abs([MyTrue/FalseField]))

substitute the correct name of the True/False field, of course.

hth
 
Thus using the fact that true = -1 and false = 0? Neat! But why can't one
use the count function with the criterion that the value = true? That would
be so much easier.

Thanks for the help.

tina said:
try

Sum(Abs([MyTrue/FalseField]))

substitute the correct name of the True/False field, of course.

hth


Arnold R said:
I have several fields in a d/b that are "true/false" type. I am trying to
display the count of the true entries in these fields. When I try to use the
count function in a query I get the total number of records in the d/b. I've
tried to use the criterion that the variable is true. Can anyone help? I
would think this would be an easy thing to do.
 
Arnold,

It depends where you are trying to display this count. You can easily
use a query to get a count of the -1 records. Just use a Totals Query,
and set the criteria as appropriate. If you are trying to put this in
an unbound textbox on an form, I would personally use the approach
suggested by Tina. But the other way that may seem more logical to you,
and no reason not to, would be to use a domain aggregate function...
=DCount("*","YourTable","[YourField]=-1")
 
Thanks for the answer. Unfortunately, what I was asking for was a solution
that didn't need any VBA knowledge. It would have seemed logical that since
one of the more common actions in a d/b is to count the number of entries
meeting some criterion that one could do that on a logical field directly in
a query. I guess you can't. I guess I'll settle for these methods, but....

Steve Schapel said:
Arnold,

It depends where you are trying to display this count. You can easily
use a query to get a count of the -1 records. Just use a Totals Query,
and set the criteria as appropriate. If you are trying to put this in
an unbound textbox on an form, I would personally use the approach
suggested by Tina. But the other way that may seem more logical to you,
and no reason not to, would be to use a domain aggregate function...
=DCount("*","YourTable","[YourField]=-1")

--
Steve Schapel, Microsoft Access MVP


Arnold said:
Thus using the fact that true = -1 and false = 0? Neat! But why can't one
use the count function with the criterion that the value = true? That would
be so much easier.

Thanks for the help.
 
There really isn't any code required for this. Just simple expressions in
control source or in queries. You could set a criteria in a query to either
true or false and then count the number of records returned.

Using Count() will count all non-null values. True and false are both not
null so they would each be counted.

--
Duane Hookom
MS Access MVP


Arnold R said:
Thanks for the answer. Unfortunately, what I was asking for was a
solution
that didn't need any VBA knowledge. It would have seemed logical that
since
one of the more common actions in a d/b is to count the number of entries
meeting some criterion that one could do that on a logical field directly
in
a query. I guess you can't. I guess I'll settle for these methods,
but....

Steve Schapel said:
Arnold,

It depends where you are trying to display this count. You can easily
use a query to get a count of the -1 records. Just use a Totals Query,
and set the criteria as appropriate. If you are trying to put this in
an unbound textbox on an form, I would personally use the approach
suggested by Tina. But the other way that may seem more logical to you,
and no reason not to, would be to use a domain aggregate function...
=DCount("*","YourTable","[YourField]=-1")

--
Steve Schapel, Microsoft Access MVP


Arnold said:
Thus using the fact that true = -1 and false = 0? Neat! But why can't
one
use the count function with the criterion that the value = true? That
would
be so much easier.

Thanks for the help.
 
Arnold,

None of the suggestions made have involved any VBA. They either involve
Functions in calculation expressions, the use of which is frequently
required in Access, or the use of a Query, which is also a basic technique.
 
Back
Top