MULTIPLE SELECTION !!

J

jay dean

Hello !

I have a combobox on a userform and it works fine. I need a macro that
will allow me to select multiple items in the dropdown list. Is this
possible at all?

Any help would be appreciated.

Thanks!
Jay



*** Sent via Developersdex http://www.developersdex.com ***
 
R

Rick Rothstein

Not completely sure, but I don't think it is possible to do that with a
ComboBox. Out of curiosity, if the user selected two or three items in your
ComboBox, what would you display in the text field... the first item? If so,
how would the user know there were other items selected and they were only
looking at one of them?
 
F

FSt1

hi
rick is right. combo boxes don't have multiselect properties. but a list box
does. so you might want to consider that.
but a disadvantage would be that, depending on the size of you list, this
might casue a redesign of your form. and the codeing might be a tad trickier.
but that just depends on how great your need for multiselect capabilities is.

regards
FSt1
 
J

jay dean

Rick, FSt1, and Dave -

Okay, if I use a listbox like you suggested and the user selects
multiple items, I need a mcro that will concatenate the selected items
into one string, maybe, store it in a string variable.

For example: Dim Mylist as String.
If a user selects 4 items in the list being: "I like" (1st slection),
"studying" (2nd selection), "vba every" (3rd selection), and "other day"
(4th selection), then
Mylist should contain "I like studying vba every other day"

**Please note that the number of selections 4 used in the above example
is just an example. In reality, the user may select 0 items, 1 item, 2
items, 3 items, 4 itmes, 5 items,... etc.

Any help would be appreciated.
Thanks
Jay



*** Sent via Developersdex http://www.developersdex.com ***
 
R

Rick Rothstein

Try code something like this...

Dim X As Long
Dim CombinedText As String
With ListBox1
For X = 0 To .ListCount - 1
If .Selected(X) Then
CombinedText = CombinedText & " " & .List(X)
End If
Next
End With
' CombinedText now has the selected items from ListBox1
' concatenated together with a blank space between items

If you need this combined text in other procedures, then the CombinedText
variable should probably be Dim'med in a Module so it is global.
 
J

jay dean

Thank you Rick...Your code works beautifully!!!
One more thing. After my listbox loads its values, it displays 6 items
at a time (per scroll). Is there a way I can increase the number of
items it dsiplays in the window from 6 to about 10?

I typically use the "ListRows" property for comboboxes, but listboxes
don't give me that option.

Thanks!
Jay


*** Sent via Developersdex http://www.developersdex.com ***
 
R

Rick Rothstein

You only have two choices as far as I can see... either make the ListBox
taller or make the Font Size smaller (although doing the latter might make
the text too small to be read).
 
J

jay dean

Thanks, Rick ! I appreciate the help.
I have redefined the scope of the problem, and implemented the solution
using a combobox, a listbox, and an activeX command. It works great.
Your inputs have saved me a lot of time.

Thanks again!
Jay



*** Sent via Developersdex http://www.developersdex.com ***
 

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