NorthbyNorthwest
Board Regular
- Joined
- Oct 27, 2013
- Messages
- 173
- Office Version
- 365
Hi, everyone. I have a group of listboxes that I check to determine if nothing selected. If nothing selected, users get a message box advising them to select at least one item. So, users get multiple message boxes if there are multiple listboxes with no selection. Is there a way to loop through this specific group of listboxes (there are other listboxes in form) and send one message advising users of all listboxes needing a selection. Example: MsgBox "Please make selections for listboxes 2 and 5." In code below iCount = 0 indicates listboxes with no selection. So, I'm guessing you have to loop through iCounts that equal zero?
VBA Code:
If OptButton2.value = True Then
For N = 0 To lbxList1.ListCount - 1
If lbxList1.Selected(N) = True Then
iCount = iCount + 1
End If
Next N
If iCount = 0 Then MsgBox "Please select at least one item from listbox 1"
End If
If optButton5.value = True Then
For N = 0 To lbxList2.ListCount - 1
If lbxList2.Selected(N) = True Then
iCount = iCount + 1
End If
Next N
If iCount = 0 Then MsgBox "Please select at least one item from listbox 2"
End If
If optButton8.value = True Then
For N = 0 To lbxList3.ListCount - 1
If lbxList3.Selected(N) = True Then
iCount = iCount + 1
End If
Next N
If iCount = 0 Then MsgBox "Please select at least one item from listbox 3"
End If
If optButton11.value = True Then
For N = 0 To lbxList4.ListCount - 1
If lbxList4.Selected(N) = True Then
iCount = iCount + 1
End If
Next N
If iCount = 0 Then MsgBox "Please select at least one item from listbox 4"
End If
If optButton14.value = True Then
For N = 0 To lbxList5.ListCount - 1
If lbxList5.Selected(N) = True Then
iCount = iCount + 1
End If
Next N
If iCount = 0 Then MsgBox "Please select at least one item from listbox 5"
End If
If optButton17.value = True Then
For N = 0 To lbxList6.ListCount - 1
If lbxList6.Selected(N) = True Then
iCount = iCount + 1
End If
Next N
If iCount = 0 Then MsgBox "Please select at least one item from listbox 6"
End If