Multiselect Listbox - identify if item picked

  • Thread starter Thread starter apndas
  • Start date Start date
A

apndas

Hello

the next conundrum i have in relation to my ongoing userform
development. basically i want to confirm that at least one item has
been selected from my listbox before allowing my commandbutton to
proceed. help!!

(this part i can do) in the event that nothing has been selected i want
to exit sub and prompt user to pick a item from the listbox - so it's
just the first bit that has me stumped. i can't use listindex because
of the multiselect function.

regards
darren
 
Seems like you have to use the _Change event instead of the _Click events to
detect a click, in Excel2K; seems bizarre as you are clicking without
changing anything.. but anyway.
Private Sub ListBox1_Change()
Dim i As Long
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
CommandButton1.Enabled = True
Exit Sub
End If
Next
End With
CommandButton1.Enabled = False
End Sub

NickHK
 
Thanks for your reply Nick - that sub works however in disabling the
command button it does not allow me to then select a manifest # and
continue processing my invoice, I just want it to alert me that nothing
has been selected and setfocus on the manifest list and be then able to
select something - that sounds a bit circular - I hope I'm making some
sense.

regards
Darren
 
You mean something like this ?

Private Sub ListBox1_Change()
Dim i As Long
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
'Do nothing
Exit Sub
End If
Next
End With
MsgBox "Missing some selection"
ListManifest.SetFocus

End Sub

NickHK
 
Hi Nick

Unfortunately that does not work, if I don't select anything in the
listbox (1 or more items) it still processes the invoice when i click
the commandbutton, i think the test needs to be in the
commandbutton_click code, which i also tried but could still not get it
to work???? aagghh!!!
 
You have the code to test if you have any selection or not, so it's up to
you decide when it is called.

NickHK
 

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

Back
Top