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?
Golfinray - 06 May 2008 18:21 GMT
2 great explainations of that: Check Martin Green at www.fontstuff.com and
Allen Browne at www.allenbrowne.com
> tHello,
> I have a multi-select list box in which the selection should be stored in a
[quoted text clipped - 5 lines]
>
> Can anyone figure out what I am doing wrong?
Linq Adams - 06 May 2008 18:50 GMT
The code for retrieving data from a multi-select listbox is different from
that for retrieving data from a single select listbox. Here's a snippet of
code from Mary McCarthy over at bytes.com that should do the job:
http://www.thescripts.com/forum/showthread.php?p=2316465#post2316465

Signature
There's ALWAYS more than one way to skin a cat!
Answers/posts based on Access 2000/2003
fredg - 06 May 2008 18:50 GMT
> tHello,
> I have a multi-select list box in which the selection should be stored in a
[quoted text clipped - 5 lines]
>
> 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.

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail