Here is code that will limit the selections in a listbox to 3 (or another number you specify). I used this code in a list box named: lstItems
You will need to substitue the actual name of your list box.
Private Sub lstItems_AfterUpdate()
If Me.lstItems.ItemsSelected.Count > 3 Then
If Me.lstItems.ItemsSelected.Count <> 0 Then
MsgBox "Only three items may be selected!", vbCritical + vbOKOnly
strEachVal = ""
For Each varItem In Me.lstItems.ItemsSelected
strEachVal = Me.lstItems.ItemData(varItem)
If InStr(1, strSelectedValues, strEachVal) = 0 Then
'this is the value that was the last one selected so unselect it
Me.lstItems.Selected(varItem) = False
End If
Next varItem
End If
Else
'write all currently select values to the "strSelectedValues" variable
If Me.lstItems.ItemsSelected.Count <> 0 Then
strSelectedValues = ""
For Each varItem In Me.lstItems.ItemsSelected
If strSelectedValues = "" Then
strSelectedValues = Me.lstItems.ItemData(varItem)
Else
strSelectedValues = strSelectedValues & "," & Me.lstItems.ItemData(varItem)
End If
Next varItem
Else
MsgBox "No items are selected from the list", vbInformation
Exit Sub 'Nothing was selected
End If
End If
End Sub
HTH