A problem like this can be a little more involved than you may initially think, due to VB's handling of events. I messed around and came up with this, which I think will do what you want. (You can open a new VB project, slap a listbox with checkbox style on the form, paste in this code, and check it out.)
VB Code:
Option Explicit Dim mblnSuppressClick As Boolean Dim mblnAfterItemCheck As Boolean Private Sub Form_Load() Dim intX As Integer For intX = 1 To 10 List1.AddItem "Person #" & intX Next End Sub Private Sub List1_Click() If mblnAfterItemCheck = True Then mblnAfterItemCheck = False Exit Sub End If If mblnSuppressClick = True Then mblnSuppressClick = False Exit Sub End If mblnSuppressClick = True If List1.SelCount > 6 Then MsgBox "A maximum of 6 people can be selected." List1.Selected(List1.ListIndex) = False Else List1.Selected(List1.ListIndex) = Not List1.Selected(List1.ListIndex) If List1.SelCount > 6 Then MsgBox "A maximum of 6 people can be selected." List1.Selected(List1.ListIndex) = False End If End If End Sub Private Sub List1_ItemCheck(Item As Integer) If mblnSuppressClick = True Then mblnSuppressClick = False mblnAfterItemCheck = True Exit Sub End If mblnSuppressClick = True If List1.SelCount > 6 Then MsgBox "A maximum of 6 people can be selected." List1.Selected(List1.ListIndex) = False End If End Sub




Reply With Quote