Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Check Boxes for multiple choice entries 2

Status
Not open for further replies.

cmwoodman

IS-IT--Management
Sep 20, 2000
32
US
I would like to know what needs to be done to make access 2k use check boxes to enter multiple items into a single field. it would be easier if i could just make a list of items and have my users just "check the ones that apply". because the list of options will most likely never change but the number of options that apply will. I really need this to put the data items that apply into one field. not into seperate fields.

any ideas? [sig][/sig]
 
In your form after update event you could just reference the available choices the user may have checked like this

Private Sub Form_AfterUpdate()
Dim str as string
If Me.firstCheckBox Then 'true
str = "the value you need to save, "
End If

If Me.secondCheckBox Then 'true
str = str & "the next value you want to save, "
End If

If Me.thirdCheckBox Then 'true
str = str & "the next value you want to save, "
End If

'do this for each of the check boxes that you have
'after you go through the list of check boxes you will
'have a str value = to the accumulated list of "True"
'check boxes seperated by a comma and a space.

If str <> vbNullString Then
Me.fieldYouWantToPlaceTheValuesIn = str
End if

End Sub

If you need to prevent the user from not making any choices and then attempt to save the record, let me know. I will post the second option.
[sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Another aproach ...

1) Set the tag property of each of the check boxes that make up your choices to &quot;Choices&quot;.
2) In the Status bar text property for the check boxes, type the &quot;value&quot; for the selection.

Dim Ctrl As Control, Selections As String, ThisSelection
For Each Ctrl In Me.Controls
If Ctrl.Tag = &quot;Choices&quot; Then
If Ctrl = True Then
ThisSelection = Ctrl.StatusBarText
Selections = Selections & &quot; &quot; & ThisSelection
End If
End If
Me![Text1] = Selections
Next

Puts the text in the statusbartext property in [text1] separated by a space.

The advantage of this approach is that you can modify the choices without rewriting the code. If you want to add a choice, you just have to stick a new checkbox on the form and set the tag and status bar text properties.

This will work with bound or unbound checkboxes.

Hope this helps. [sig]<p>Dave<br><a href=mailto:gallagherd@earthlink.net>gallagherd@earthlink.net</a><br>[/sig]
 
DaveSH, great code! Your the man! [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top