Multi Select Listbox Code

A

Alex

I need the code that will copy multiple selected items from a list box into
another list box on the same form.

thanks

in advance
 
D

Douglas J. Steele

Assuming that Listbox1 and Listbox2 are both configured to allow 1 column
only, try something like the following untested air code to set Listbox2 to
have those items selected in Listbox1:

Dim strRowSource As String
Dim varSelected As Variant

For Each varSelected In Me.Listbox1.ItemsSelected
strRowSource = strRowSource & _
Me.Listbox1.ItemData(varSelected) & ";"
Next varSelected

If Len(strRowSource) > 0 Then
strRowSource = Left(strRowSource, Len(strRowSouce)-1)
End If

Me.Listbox2.RowSourceType = "Value List"
Me.Listbox2.RowSource = strRowSource
 
A

Alex

When I run your code I get the following error:
method 'item' of object 'forms' failed
 
D

Douglas J. Steele

I did warn you it was air-code! <g>

What line is it complaining about? Since I'm not using a method named Item
anywhere in that code, nor am I addressing the Forms collection anywhere, I
somehow suspect it's complaining about something else in your code.
 
Top