Multi selection with checkboxes

marathonlady

Registered User.
Local time
Today, 02:54
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...)
 
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
 
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
 

Users who are viewing this thread

Back
Top Bottom