Multiselect listbox if no selection
You do have to go through the list box an item at a time. You could quit
the loop as so as you find a selected item though.
Dim SomethingSelected as Boolean
With lst_Comp_Lv
For i = 0 To .ListCount - 1
If .Selected(i) Then
SomethingSelected = True
Exit For
End If
Next i
End With
If Not SomethingSelected Then
MsgBox "There was nothing selected."
End If
--
Jim
"BigPig" wrote in message
...
| Hi All,
|
| I have a listbox that is multiselect. I want to find a way to figure out
if
| anything is selected, if not "do something". I wrote this which works, but
I
| have to think that there is an easier way.
|
| Dim Z As Integer
| Z = 0
| With lst_Comp_Lv
| For i = 0 To .ListCount - 1
| If .Selected(i) Then
| Else
| Z = Z + 1
| End If
| Next i
| End With
|
| If Z = lst_Comp_Lv.ListCount Then
| MsgBox "There was nothing selected."
| Exit Sub
| End If
|
| I also tried:
|
| If lst_Comp_Lv = Null Then
| MsgBox "There is nothing selected."
| Exit Sub
| End If
|
| But that didn't work.
|
| Any suggestions or advice you could provide would be greatly appreciated.
| Thank you.
|
|