Listbox - limit selection

G

Guest

I have a listbox based on a table and I want the user to be able to either
select the first item which is a * OR make multiple selections from the list.
If the * is selected then the user should not be able to make other
selections.

Thanks
 
G

Guest

Use the listbox's Change event. You can tell if the "*" is selected by using
the ListIndex property. If the selected item is "*", then set the
MultiSelect property to 0. Now, the trick is, what if a user selects items
other than * first,then goes back and selects the *?
 
D

Douglas J Steele

Sorry, Klatuu, but I don't think that'll work.

From the Help file entry for MultiSelect property "This property can be set
only in form Design view."

I think the only solution is to put logic in the list box's BeforeUpdate
event:

Private Sub MyListbox_BeforeUpdate(Cancel As Integer)
If Me.MyListbox.ItemsSelected.Count > 1 Then
If Me.MyListbox.Selected(0) = True Then
MsgBox "Can't select * with any other values"
Cancel = True
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top