Multi selection with checkboxes

marathonlady

Registered User.
Local time
Yesterday, 19:34
Joined
Jul 10, 2002
Messages
120
On my form I want the user to be able to select several checkboxes at a time, like you can with a list box. Except with a listbox you have a property multi select. How do you set the checkbox to be multi select.

Thanks.
 
? A check box can either be checked, or not checked ?


kh
(Unless those whiz kids from MSft done come up with a new control...)
 
I think you are referring to a group of check boxes in an option group. I’m afraid that you cannot have Multi select check boxes in an option group, it defeats the object of having an option group selection! The more helpful name for an option group is “Radio Buttons” this term is derived from the old fashioned car radio where you had a set of great big buttons. As you push one in, the selected one popped out. Obviously you could only listen to one radio station at a time. I had great fun as a kid trying to make two or more buttons stay in at the same time much to the annoyance of my dad.

The attached example shows you how to loop through a collection of check boxes and do something if the check box is checked.

The check boxes have to be named something like check1, check2, check3.

I adapted the code from the Microsoft help file, it’s a bit long winded, if it can be shortened I would be interested to see how as I have tried several things with no success.
 

Attachments

Mmmm... very interesting....

Is there any way to adapt this so that if a user selects 5 out of 30 check boxes, these can be the selections for a report?

For example, Set up 10 options that can be checked and become rows in a report and have another 3 checkboxes that can become the value?

That would be great and would allow the user to customise their own reports....does this make sense to try and do?
Thanks,
Mandy
 
>>>....does this make sense to try and do?<<<

Yes, I think so, but I would need more information on what you actually want to do.

I can't do anything at the moment, I'm too busy to "play" but I thought it was worth mentioning that I am working on a popup form that displays a collection of check boxes, where each check box is named to represent an option selectable in a sub form.

I have found that some users like to see the available options with a check box against each option showing whether it has or has not been selected, and they can also select or deselect options in the same display.

However in most instances instances this would require the hard coding of the check boxes and options names into a form, and this is obviously to be avoided because any changes to the available selections means that the programmer needs to modify the hard coded form.

So I have developed, am developing, a popup form that displays the information from the sub forms look up table as a collection of checked and unchecked check boxes where the relevant items are or are not selected. The user can also select or deselect a check box and this is instantly reflected in the subform.
 
That code's pretty terse, Tony. Not sure you're going to be able to pare it down much! If you don't want to have to stick to your naming convention of Checkbox1, Checkbox2 etc. you could use a construct like this to do the same thing.

In the Tag Property for the desired checkboxes (or any controls, for that matter) enter a Tag. This example uses marked, but it could be anything. Then

Code:
Dim ctrl As Control

For Each ctrl In Me.Controls
    If ctrl.Tag = "marked" Then
       ctrl.Enabled = False
    End If
   
 Next

This code enables the controls in question, but you could do other things as well, such as building the string for your messagebox.

Note that you do not use the double quotation marks when entering the Tag, but you do use the double quotation marks in code when referring to it.
 
leave the ControlSource blank (unbound).
add the Column (field) to the form. you may need to set its Visible Property to No, so that it will not be visible.
then identify the Names of the Label associated with your check box.
on the Current event of the Form:
Code:
Private Sub Form_Current()
Me.Checkbox1Name = (Instr(Me.ColumnName, Me.label1Name.Caption)>0)
Me.Checkbox2Name = (Instr(Me.ColumnName, Me.label2Name.Caption)>0)
Me.Checkbox3Name = (Instr(Me.ColumnName, Me.label3Name.Caption)>0)
now before saving the form, your Column should have the values you checked on the
checkboxes.
add code to BeforeUpdate event of the Form:
Code:
Private Sub Form_BeforeUpate(Cancel As Integer)
Dim strValue As String
strValue = strValue & IIF(Me.Checkbox1Name, Me.label1Name.Caption & ", ", "")
strValue = strValue & IIF(Me.Checkbox2Name, Me.label2Name.Caption & ", ", "")
strValue = strValue & IIF(Me.Checkbox3Name, Me.label3Name.Caption & ", ", "")
If strValue <> "" Then
    strValue = Left(strValue, Len(strValue)-2)
End If
Me.ColumnName = strValue
End Sub
 
I want the selected options to be present in one column of the database.

I suspect you meant Row?

However, storing information in a column is much more preferable than storing it in an individual field in a row.

Yes I know, I just read it and it didn't make much sense to me either!

There's a lot of ways of sorting out your question, I'm not going into any great detail on what I'm thinking, because I'm not sure you have identified the real question. "MIR"

That acronym is for a bunch of people on here who keep using bloody acronyms and I don't know what they mean by them, and when I ask they don't tell me!
 
I have made two other answers to this thread one 15 years ago and one 11 years ago!

Without looking at it, as I'm on my mobile, I think the sample file here might have some interesting VBA code in it you could use for option groups:-

https://www.niftyaccess.com/option-group-label-color-change/

And this one:-
https://www.niftyaccess.com/loop-through-a-set-of-controls/

mind you I think they only handle individual selections not multiple selections.

This idea I had could manage multiple selections:-

https://youtu.be/X12J9-6RRpc

Sent from my Pixel 3a using Tapatalk
 

Users who are viewing this thread

Back
Top Bottom