List Box Selection

  • Thread starter Thread starter Dean Simpson
  • Start date Start date
D

Dean Simpson

Does anyone know another way of knowing when a list box has been selected
other then

if listbox.column(0) = "value"

Thanks in adavnce
 
You don't need to use the Column() property if it is the bound column you
are interested in. Just:
If Me.MyListbox = "value" Then

If you want to know whether anything is selected, use IsNull(), i.e.:
If Not IsNull(Me.MyListbox) Then

If it is multi-select list box, things are different again. Check its
ItemsSelected.Count.
 
A quick loop to go through each row;

Dim intCur_Row as Integer
Dim booSelected as Boolean

For intCur_row = 0 to listbox.listcount
If listbox.Selected(intCur_Row) = true then
booSelected = True
Exit For
End If
Next intCur_Row

Then test if it is selected with;

If booSelected = True Then ***Enter Command***

Hope this helps.
Steve.
 
Thanks for response

The list box isn't bound so I used your second suggestion and it work great.
I was using the 'If listbox.column() > "0" Then' which sometimes gave me
problems with text, dates and numbers being used in my app. But this works
a treat for what I need

Thanks
 
I might misunderstand the question but if I understand then the following
should work:

if listbox.ListIndex <> -1
 
Back
Top