Holy Inquisitor
New Member
- Joined
- Sep 17, 2013
- Messages
- 9
I managed to come up with the following code for a checkbox group including 5 checkboxes.
Although it limits the possible selections to maximum 2, when 2 checkboxes are already selected it not always disables all other unselected checkboxes and in this case one of the previously selected checkboxes will become unchecked.
Can anyone help me how to make the code more accurate.
Thank you
Private Sub TwoPicksOnly(sGroup As String, sName As String)
Dim ole As OLEObject
Dim CheckedBoxCount As Integer
CheckedBoxCount = 0
For Each ole In Me.OLEObjects
If TypeName(ole.Object) = "CheckBox" And ole.Object.GroupName = sGroup And ole.Object.Value = True Then CheckedBoxCount = CheckedBoxCount + 1
If CheckedBoxCount > 2 And ole.Object.GroupName = sGroup Then ole.Object.Value = False And ole.Object.Enabled = False
Next ole
End Sub
Although it limits the possible selections to maximum 2, when 2 checkboxes are already selected it not always disables all other unselected checkboxes and in this case one of the previously selected checkboxes will become unchecked.
Can anyone help me how to make the code more accurate.
Thank you
Private Sub TwoPicksOnly(sGroup As String, sName As String)
Dim ole As OLEObject
Dim CheckedBoxCount As Integer
CheckedBoxCount = 0
For Each ole In Me.OLEObjects
If TypeName(ole.Object) = "CheckBox" And ole.Object.GroupName = sGroup And ole.Object.Value = True Then CheckedBoxCount = CheckedBoxCount + 1
If CheckedBoxCount > 2 And ole.Object.GroupName = sGroup Then ole.Object.Value = False And ole.Object.Enabled = False
Next ole
End Sub