TOGGLE BOX

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way that have a toggle button box but be able to select multiple
items and store that selection in one single field?

Example Test1
Test2
Test3

The user selects test 1 and 2 and both of those selections are stored in one
single field.

Thanks so much
 
Vic,

What's a toggle button box? I think you mean you want to be able to select
multiple CheckBoxes, and have the selection stored somewhere, so when you
re-open the form, your selection will be returned.

There is no native way of doing this, however, you can do one of two things.

Firstly, you can add a table field to record the value of each check box.
Secondly, you can add a single Integer field to the table, and use binary
numbers to represent each check box selection.

For example, if we have, say, four check boxes - BoxA, BoxB, BoxC and BoxD.
We assign the boxes a unique value, which when combined, allows us to
determine which one has been selected. So we assign the following values:
BoxA = 1
BoxB = 2
BoxC = 4
BoxD = 8

When you save the record, just add up the values for each ticked box, and
store that value in the Integer field:
Me!txtValue = 0
If Me!BoxA Then Me!xtValue = 1
If Me!BoxB Then Me!txtValue = Me!xtValue + 2
If Me!BoxC Then Me!txtValue = Me!xtValue + 4
If Me!BoxD Then Me!txtValue = Me!xtValue + 8

When you open the form, or navigate to a new record, use the following code
to set the status of each box:
If Nz(Me!txtValue, 0) > 0 Then
Me!BoxA = ((Me!txtValue AND 1) > 0)
Me!BoxB = ((Me!txtValue AND 2) > 0)
Me!BoxC = ((Me!txtValue AND 4) > 0)
Me!BoxD = ((Me!txtValue AND 8) > 0)
End If

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
The best way to do this is to create a related table, with a record for each
selection.

One of the basic rules of data normalization is not to store more than one
thing in a field. You are severely limiting yourself if you concatenate the
items into a delimited string and store them all in one field. Not worth the
effort it takes to write the code.
 
Back
Top