Multi-Select LIst Box Not Appearing in Text Box

P

Pattyt

tHello,
I have a multi-select list box in which the selection should be stored in a
bound text field on my main form. My problem is that when I select multiple
items from my list box the selections don't appear in the text box. If I go
back to the list box properties and assign a "none" to multi select property
and I then select one item from the list box, my selection appears in the
text box.

Can anyone figure out what I am doing wrong?
 
F

fredg

tHello,
I have a multi-select list box in which the selection should be stored in a
bound text field on my main form. My problem is that when I select multiple
items from my list box the selections don't appear in the text box. If I go
back to the list box properties and assign a "none" to multi select property
and I then select one item from the list box, my selection appears in the
text box.

Can anyone figure out what I am doing wrong?

You need code to extract the selected values from a multi-select list
box. You don't need code if the list box is not multi-select.

You can code the list box's Exit event....
Private Sub ListBoxName_Exit(Cancel As Integer)
' read the selected values

On Error GoTo Err_Handler
Dim strValue As String
Dim varItem As Variant
For Each varItem In Me.ListBoxName.ItemsSelected
strValue = strValue & Me.ListBoxName.ItemData(varItem) & ", "
Next varItem
strValue = Left(strValue, Len(strValue) - 2)
Me.ControlName = strValue

'Then clear the items from the list box
For Each varItem In Me.ListBoxName.ItemsSelected
ListBoxName.Selected(varItem) = False
Next varItem

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 5 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub

End Sub

this will display in a Form's control like this ....
Red, Blue, Green, Orange

However, STORING more than one value in a field is NOT a good idea.
The usual method of storing more than one value in a field for a
record is to use a sub-table bound to the main table by an ID field.
Then you can store as many values as you like as individual records in
the sub-table that are bound to a record in the main table.
 

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