Selecting Multiple values from a list

Affliction

New member
Local time
Today, 16:37
Joined
Jun 2, 2003
Messages
6
I was wondering if there is a way to select multiple values from a list box to be stored in one field? I am doing a survey, and one question has the ability to be more than one answer, so I am wondering if multiple values can fit in ONE field? I tried using a form, but the form doesn't store the values ... can someone advise me? Thanks
 
What I would do is loop through the selecteditems collection of the listbox and concatenate comma separated values in a string. Then store the string in the desired textbox.

Like

Private Sub myList_LostFocus()
Dim strList As String
strList = ""
For Each Item In myList.ItemsSelected
strList = strList & myList.ItemData(Item) & ", "
Next
strList = Left(strList, Len(strList) - 2)
myTextBox = strList
End Sub
 
Isn't that some VB Script?
 
Yes, it is code that runs when the listbox loses focus. Do you need help implementing it?
 
On your form, do you have the list box and the textbox that you would like to store the values selected? If so, what are the control names of the listbox and textbox. (Right click, select properties then look at Name on the All tab)
 
What is the NAME of the listbox control, and the NAME of the textbox control on your form?
 
name of the listbox control is "clothing"

there isn't any textbox
 
add a textbox named txtClothing to the form and set the control source for txtClothing to the field in your table that you want to store the clothing value in.

Then from the properties menu of the listbox clothing, click the Events tab. Then click the LostFocus row. When you click the LostFocus row three dots (ellipsis ...) will appear. Clicking those dots will open the code window. Copy the following code and paste it between the Private Sub and End Sub statements

Dim strList As String
strList = ""
For Each Item In Clothing.ItemsSelected
strList = strList & Clothing.ItemData(Item) & ", "
Next
strList = Left(strList, Len(strList) - 2)
txtClothing = strList
 

Users who are viewing this thread

Back
Top Bottom