Count check box yes/no

G

Guest

I have a table with yes/no checkboxes. I want to be able to count the number
of times yes is checked in a field.

I have created a query that counts the fields, but it count all checkboxes,
not just the ones that have been checked yes.

Does anyone have any ideas?
 
K

Ken Snell \(MVP\)

Use the Sum aggregate function. When a checkbox is checked, its numeric
value is -1 (which is how ACCESS represents True or Yes). Using the Abs
function changes the negative sign to plus so that you get a positive number
as the result.

NumberChecked: Abs(Sum([CheckboxFieldName]))


Or as an SQL example:

SELECT Abs(Sum([CheckboxFieldName])) AS NumberChecked
FROM TableName;
 
B

banem2

Use the Sum aggregate function. When a checkbox is checked, its numeric
value is -1 (which is how ACCESS represents True or Yes). Using the Abs
function changes the negative sign to plus so that you get a positive number
as the result.

NumberChecked: Abs(Sum([CheckboxFieldName]))

Or as an SQL example:

SELECT Abs(Sum([CheckboxFieldName])) AS NumberChecked
FROM TableName;
--

Ken Snell
<MS ACCESS MVP>






I have a table with yes/no checkboxes. I want to be able to count the
number
of times yes is checked in a field.
I have created a query that counts the fields, but it count all
checkboxes,
not just the ones that have been checked yes.
Does anyone have any ideas?


There is another interesting way to count Yes fields. Add in query
field:

NoOfYes: -Sum([YesNoField])

Turn on Totals and set field as Expression.

Regards,
Branislav Mihaljev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top