How to total checks in checkboxes?

Shinken

Registered User.
Local time
Yesterday, 23:19
Joined
Oct 5, 2002
Messages
14
I have a table with several checkboxes, to denote tests passed. A checked box denotes a passed test, an unchecked box denotes a failed test.

For example:

[ ] part1
[ ] part2
[ ] part3
[ ] part4
[ ] part5

Another table lists the participant's characteristics, such as Date of Birth, Gender, etc.

A simple query (qryTestResults) combines both tables, which are related by an ID number.

I wish to develop a report that shows the total number of each passed test, separated by Gender and age above & below 25 yrs.

I would like the results to look something like this (note that I'm using periods only to set the row heading spacing in this message)

.........................Part1....Part2....Part3....Part....Part5
Male <25
Male >= 25
Female <25
Female >= 25

I'm having two problems.

1. What expression do I use to count the total number of checked checkboxes in each category/column (part1, part2, etc)?

2. Can I do this in a single crosstab query, or should I use 2 (or more) crosstab queries, one for Gender=Male and one for Gender=Female?

I'm assuming that whatever query(s) I use, should be based on the simple query (qryTestResults), but I may be wrong, and perhaps should take the data directly from the 2 tables.

I somehow need to get the data into a single crosstab query so that I can create a chart of the results.

All suggestions are appreciated.

Thanks,

Shin
 
Unzip this file. The solution can be found in this sample database I created under the Union Query (qryTestResults).
 

Attachments

Why the goodluck password?
 
Last edited:
As a DBA, it's just force of habit. Consider it part of the new homeland security initiative

;)
 
It's been breached, easily;) Might the "homeland" security need reviewing
 
If you've downloaded EnderG's example (love it when someone else provides the sample data) and don't want to mess with five queries, you could achieve the same results with this:
Code:
SELECT [gender] & IIf([gender]="F","emale","ale") & IIf(age([DOB])<25,"< 25",">=25") AS Cat, abs(Sum(tblPassFail.Part1)) AS [Part 1], 
abs(Sum(tblPassFail.Part2)) AS [Part 2], 
abs(Sum(tblPassFail.Part3)) AS [Part 3], 
abs(Sum(tblPassFail.Part4)) AS [Part 4], 
abs(Sum(tblPassFail.Part5)) AS [Part 5]
FROM tblPassFail INNER JOIN tblStudents ON tblPassFail.ID = tblStudents.ID
GROUP BY [gender] & IIf([gender]="F","emale","ale") & IIf(age([DOB])<25,"< 25",">=25");
To make this work, you'll need Function Age()
Code:
Function Age(pDOB As Date) As Integer
Age = DateDiff("yyyy", pDOB, Date) - IIf(Date < DateSerial(Year(Date), Month(pDOB), Day(pDOB)), 1, 0)
End Function
 
Awww, Rich. Inquiring minds want to know. C'mon, share the love...
 
Eureka - I've struck gold. Thanks to everyone for the replies.

The winner is RASKEW - thanks much! Your code produced exactly what I was looking for. Also, the Age() function was elegant, saving me from having to use #xx/xx/xx#.

Shin
 

Users who are viewing this thread

Back
Top Bottom