Full Version: Storing multiple check box selections in one field
UtterAccess Forums > Microsoft® Access > Access Forms
chuckf1
I'm developing a survey for a school that questions category of classes such as English, math, history, etc.
The student can check as many as they want using check boxes.
I want to store their selections in one field and be able to run reports against this field to determine number of math students, english student, etc.
Chould this table field be a modulo number ?
Is there a VB algorithm for combining these 15+ check boxes ?
Thanks in advance.
dannyseager
Welcome to UA.
I'm not clear what you are trying to do... but storing them all in 1 field doesn't sound right.
Can you provide more details?
chuckf1
Check boxes provide a binary choice for a specif class catagory. If there are four different catagoryies (check boxes) and a bit-position is assigned to each one then we have 16 different combinations for the composite field starting at 0000 and ending at 1111. If position 1 is math, position 2 is english, position 3 is language and position 4 is hisory. In one 4-bit integer I can determine a students courses.
Does this make sense ?
huck
jhardy66
I don't know if you can combine the check boxes, but you should be able to just create a table with the appropriate amount of fields and do it that way without too much of a problem. It shouldn't be that much extra coding.

Welcome to UtterAccess.
chuckf1
Ideally - doing the algorithm in VB in the form is the solution I'm looking for.
Chuck
jhardy66
Could do an if-else statement.
If Me.ckb1 = True And Me.ckb2 = True Then
[Tables]![tblYourTable]![YourField] = 0011
If Me.ckb1 = True And Me.ckb2 = False Then
[Tables]![tblYourTable]![YourField] = 0010
etc...
Seems like a hard way to do it, but there may be an easier way to do it through code.
chuckf1
Is there a way to do this in VB. I seem to recall the ">>" operator to slide bits around but I'm not to sure of the syntax. Are there bit operators in VB ?
SerranoG
If you have 15 checkboxes in your form, they're either set to zero (False) or -1 (True). Suppose you have a button to sum up their choices. On the button's ON CLICK event, you can put this, assuming the summary (string of ones and zeroes, e.g. "001100" is in the textbox txtClassSummary):
!--c1-->
CODE
    Dim ctlControl as Control, strSummary as String
    
    strSummary = ""
    For Each ctlControl in Me
        If ctlControl.ControlType = acCheckBox Then
            strSummary = strSummary & CStr(ABS(ctlControl.Value))
        End If
    Next ctlControl
    
    Me.txtClassSummary = strSummary

What will happen (and I didn't test this) is that it will cycle through each checkbox. If it's TRUE (checked), then the value of the checkbox is -1. The absolute value of the checkbox will equal 1. It will be added to the string. If the checkbox is FALSE (unchecked), its value will be 0. A zero will be added to the string, etc. The CStr function changes value into a real string. You'll end up with a 15-character string made up of ones and zeroes.
This code assumes you set the TRIPLE STATE property of all checkboxes OFF and that there are no other checkboxes for other info on your form.
chuckf1
By Jove I think your algoritnm may work.
I'll try it tomorrow.
Thanks
Jack Cowley
I do not agree with your approach as I think you are going to find it very hard to come up with your totals for a report. What if you want to add another category to your list? The way you are doing it now means you need to revise your table, forms, code etc, and it will mean a lot of code to loop though each record and get the data you want. I strongly suggest you normalize your data and then getting your date will be very easy... Sample tables might look like this:
blChildren
ChildID (PK and auto)
LastName
FirstName
tblQuestions
QuestionID (PK and auto)
Question
tblChildResponses
ChildResponseID (PK and auto)
ChildID (FK)
QuestionID (FK)
Response (Yes/No)
You don't give very much information on how you are setting up your data, but this should give you some ideas.
Jack
dannyseager
thanks jack, that was what i tried to say in my post but time and details were short when i wrote it
Jack Cowley
Danny -
o problem! I did not mean to jump on anyone's toes, but it seemed to me that it was getting more complicated than necessary...
Jack
dannyseager
>
Doesn't everything frown.gif
Thanks though, you're right it was getting too complicated.
Jack Cowley
It was just my opinion that things were getting a bit far afield for a relational database.... Whatever ultimately works for the member works for me...
ack
chuckf1
Wow - You guys are great.
I'll try Greg Serrano's algorithm when I can get back to it.
Thanks to all,
Chuck
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.