multi-select listbox transferring

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

I have the states in a listbox on a popup form that is
opened from a main form. The user selects the state and
then uses a button to transfer the state over to a textbox
on the main form. The listbox MultiSelect property is set
to None. If I change the setting to Simple or Extended, I
can not get the right coding that will allow the
transfer. Here is the current line that is used allowing
one state at a time to be moved. The vbCrLf is used so
the state names show listed in the textbox rather then on
the same line.
**********
Forms![usrfrmCarriers].Form![States].Text = Me!
lstStates & vbCrLf & Forms![usrfrmCarriers].Form!
[States].Text
**********
Any help to get multiple selections to move at the same
time will be appreciated.
Thanks to anyone who assists.
*** John
 
With a multiselect listbox, you can't just use the value (I recommend for both the listbox
and textbox that you use the value property instead of the text property for what you are
doing, if the listbox has a different bound column, use the column property to get the
value from the column you want). In a multiselect listbox you have to cycle through the
selected items.

Example:

Dim varItem As Variant, strStates As String
For Each varItem in Me.lstStates.ItemsSelected
If strStates = "" Then
strStates = Me.lstStates.ItemData(varItem)
Else
strStates = strStates & vbCrLf & Me.lstStates.ItemData(varItem)
End If
Next
Forms![usrfrmCarriers]![States] = strStates
 
Back
Top