Applecore Pages on Microsoft Access

Counting True/False fields

If you want to count the number of Yes/No fields in a table that are either True or False, then you can use the fact that internally these values are stored as numeric bits. In Access, True is -1 (some other systems have it equal to 1) and False is equal to 0. So, to count the number of Yes's, you can add then Absolute value of the fields:

=Sum(Abs(blnField))

If you are only ever going to use this on data from Access, then you can do away with the Absolute value in order to save time. To count the number of No's, just add the values of 1 added to the field:

=Sum(blnField+1)

This means that any fields that are False will give a value of 1 for addition, and any True fields will produce a value of 0 (-1+1) in Access. If you are using data that stores True as 1, then this will need to be re-worked slightly:

=Sum(Abs(blnField-1))

which will give False a value of -1, and True a value of 0.

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:59:43