Multi-Select List Box Limit

agehoops

Registered User.
Local time
Today, 18:41
Joined
Feb 11, 2006
Messages
351
How do I set a limit to the number of selections in a list box? I've used the following to check how many are selected, but how do I then tell it not to allow new additions, but it can remove current ones. Obviously I can't lock it or disable it as I then wouldn't be able to de-select them, so I'm a bit stuck,thanks.

Code:
If List2.ItemsSelected.Count = 6 Then
 
How do I set a limit to the number of selections in a list box? I've used the following to check how many are selected, but how do I then tell it not to allow new additions, but it can remove current ones. Obviously I can't lock it or disable it as I then wouldn't be able to de-select them, so I'm a bit stuck,thanks.

Code:
If List2.ItemsSelected.Count = 6 Then

Place this code in the Before update event for your list box

Code:
Private Sub List2_BeforeUpdate(Cancel As Integer)
If Me.List2.ItemsSelected.Count > 6 Then
    MsgBox "You have selected too many entries!!!"
    Me.List2.Selected(Me.List2.ListIndex) = False
End If
End Sub

Obviously you'll need to change List2 to whatever your listbox is called.
 
ahh fantastic, works perfectly, just what I wanted, thanks very much :D
 

Users who are viewing this thread

Back
Top Bottom