Why is it in 6 separate fields? That sounds like a repeating group, which is
a violation of database normalization rules. It's far easier to have 6 rows
in a child table, rather than 1 row with 6 repeating fields.
If you're stuck with that design, you can try normalizing your data through
the use of a UNION query:
SELECT Id, FIeld1, Field2, 1 As TestNumber, Test1 As TestResult
FROM MyTable
UNION
SELECT Id, FIeld1, Field2, 2 As TestNumber, Test2 As TestResult
FROM MyTable
UNION
SELECT Id, FIeld1, Field2, 3 As TestNumber, Test3 As TestResult
FROM MyTable
....
UNION
SELECT Id, FIeld1, Field2, 6 As TestNumber, Test6 As TestResult
FROM MyTable
Now, it's a simple query to determine how many Yeses were answered for each
Id:
SELECT Id, Field1, Field2, Abs(Sum([TestResult]))
FROM MyUnionQuery
GROUP BY Id, Field1, Field2
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
koshti said:
The text are in separate fields. I tried the following & it worked. (The
Test1, Test2 ...etc are different text fields which hold the text string "Y")
:
Total of Y: IIf([Test1]="Y",1,0)+IIf([Test2]="Y",1,0) ............
+IIf([Test6]="Y",1,0)
However, I would like to get rid of typing so many fields. I tried but
didn't work :
IIf( Between [Test1] And [Test6]="Y",1,0
If you can make the above work too, it will save several hours of work for
me. Thanks!
Jeff Boyce said:
Do you have a text string without any "dividers" between the "Y"s and "N"s,
or are there spaces or some other character between them? Is this
consistent?
If you do have delimiters, you could consider importing into Excel and using
the "parse" function to split the string into individual cells, each
containing a single "Y" or "N".
If you have to do this inside of Access, you'll need to learn enough about
VBA to create a procedure that accepts a string and counts the number of
characters that match a character you supply. The general approach
(non-functional, not-even-psuedo-code) is:
you
are checking and go back to the third step, UNLESS there are no more
characters in the string
Regards
Jeff Boyce
Microsoft Office/Access MVP