Multiple checkbox to input multiple text into a single field...HEL

  • Thread starter Thread starter SuperNerd
  • Start date Start date
S

SuperNerd

Hi All,

I have a form with 6 check boxes, unbound. What I want to do is when check
box one is marked true, I want "1" to be input into a field; when check box 1
and two is check, I wanted to have "1 +2" to be input into the desire
field...and so on. I have 6 check boxes so I want to be able to have all the
possible combinations and I do not know which method to use. Could someone
show me how to make these 6 check boxes to have all possible combination....

Thanks in Advance
 
SuperNerd said:
Hi All,

I have a form with 6 check boxes, unbound. What I want to do is when
check
box one is marked true, I want "1" to be input into a field; when check
box 1
and two is check, I wanted to have "1 +2" to be input into the desire
field...and so on. I have 6 check boxes so I want to be able to have all
the
possible combinations and I do not know which method to use. Could
someone
show me how to make these 6 check boxes to have all possible
combination....


Could you clarify a little bit, please? Do you want the output field to
have an actual text value; e.g., "1 + 2 + 4" if check boxes 1, 2, and 4 are
checked? Or do you want to add up the numbers, so that the output field
would have the value 7 if those three boxes are checked?

Do you need to work backwards, as well? That is, do you also need the
ability to make the state of the check boxes correspond to a given value of
the "combined" field?
 
SuperNerd said:
Hi All,

I have a form with 6 check boxes, unbound. What I want to do is when
check
box one is marked true, I want "1" to be input into a field; when check
box 1
and two is check, I wanted to have "1 +2" to be input into the desire
field...and so on. I have 6 check boxes so I want to be able to have all
the
possible combinations and I do not know which method to use. Could
someone
show me how to make these 6 check boxes to have all possible
combination....


I should mention that combining multiple data into a single field is
generally a violation of relational database principles, so while it's
certainly possible to do this, it isn't at all clear to me that it's
something you should do. Perhaps if you'd explain some of the background of
your request, we could see a better way to accomplish your goals.
 
There is a way to do this

Assign values to your checkoff boxes using a binary series:

EXAMPLE: You have the following checkoff boxes and values:

Active (Value=1)
Average Weight (Value=2)
Unlimited Mobility (Value=4)
Other (Value=8)

(Note the binary series: 2^0, 2^1, 2^2, 2^3)
You want to store the data in this field: PhysicalAssessment

Check off any combination of them, the number will be unique. Use VBA to sum the values and place the new value in PhysicalAssessment.

Check Active and Unlimited Mobility, 1+4=5.
Check Active and Other, 1+8=9.
Other, 8.
Check Active, Average Weight and Unlimited Mobility, 1+2+4=7.

You'd use code to sum and save the value.

The hard part would be retrieving the original data. Again, maybe a coding issue? Look for the number in our series (1,2,4,8) that is less than the value in PhysicalAssessment. Subtract it. For example, 5-4=1. 4=Unlimited Mobility, 1=Active.

For the value of 7, 4 is the first number to use. 7-4=3. 3-2=1. 1-1=0. We can see these are the values for Unlimited Mobility, Average Weight and Active.:)

I've seen a better explanation of this, but can't find it - anyone?
 
I want multiple text to appear like you "1+2+3+4+5+6"

thanks for the quick respond...
 
I want the output to have the actual text as "1+2+4" to appear if check boxes
1,2,4 is checked. Thanks for the quick respond...
 
SuperNerd said:
I want the output to have the actual text as "1+2+4" to appear if check
boxes
1,2,4 is checked. Thanks for the quick respond...

This is easiest if the names of the check boxes are all the same except for
a numeric suffix from 1 to 6; in other words, you have (for example) check
boxes named "chkOption1", "chkOption2", "chkOption3", ... and so on up to
"chkOption6". Then you can write a function in the general section of the
form module like the following:

'----- start of code -----
Function SetOptionsFromCheckBoxes()

Dim I as Integer
Dim strOptions As String

For I = 1 to 6
If Me.Controls("chkOption" & I) = True Then
strOptions = strOptions & "+" & I
End If
Next I

If Len(strOptions) > 0 Then
strOptions = Mid$(strOptions, 2)
End If

Me!CombinedOptions = strOptions

End Function
'----- start of code -----

That also assumes that you want to store the string of all selected options
in a field I'm calling "CombinedOptions".

Now, with this function in the form's module, you have to ensure that it is
called any time the any of the 6 check boxes is updated. To do that, you
can put the following function expression in the AfterUpdate event
property -- right on the property sheet -- of each of the text boxes:

=SetOptionsFromCheckBoxes()

Then, any time one of the check boxes is checked or unchecked, the value of
CombinedOptions will be changed accordingly.
 
Thanks a lot!!! This works great...

Dirk Goldgar said:
This is easiest if the names of the check boxes are all the same except for
a numeric suffix from 1 to 6; in other words, you have (for example) check
boxes named "chkOption1", "chkOption2", "chkOption3", ... and so on up to
"chkOption6". Then you can write a function in the general section of the
form module like the following:

'----- start of code -----
Function SetOptionsFromCheckBoxes()

Dim I as Integer
Dim strOptions As String

For I = 1 to 6
If Me.Controls("chkOption" & I) = True Then
strOptions = strOptions & "+" & I
End If
Next I

If Len(strOptions) > 0 Then
strOptions = Mid$(strOptions, 2)
End If

Me!CombinedOptions = strOptions

End Function
'----- start of code -----

That also assumes that you want to store the string of all selected options
in a field I'm calling "CombinedOptions".

Now, with this function in the form's module, you have to ensure that it is
called any time the any of the 6 check boxes is updated. To do that, you
can put the following function expression in the AfterUpdate event
property -- right on the property sheet -- of each of the text boxes:

=SetOptionsFromCheckBoxes()

Then, any time one of the check boxes is checked or unchecked, the value of
CombinedOptions will be changed accordingly.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
I am trying to do something similar to this. However, I am trying to have
certain values displayed if check boxes are checked.

For example,
checkbox 1 = blue
checkbox 2 =green
checkbox 3 =red

If checkbox 1 and 3 are checked I want to display "blue red".

How can I do this?

Thanks.
 
chinny03 said:
I am trying to do something similar to this. However, I am trying to have
certain values displayed if check boxes are checked.

For example,
checkbox 1 = blue
checkbox 2 =green
checkbox 3 =red

If checkbox 1 and 3 are checked I want to display "blue red".

How can I do this?

Where do you want to display the information? You could have a text box
with an expression like this as its controlsource:

=Trim(IIf([Checkbox1], "blue ", "") & IIf([Checkbox2], "green ", "") &
IIf([Checkbox3], "red", "")
 
Back
Top