By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,513 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

listbox question

P: n/a
I have a form which contains a multiple selection list box. How can I use
the list box so that all items selected are added to the record of it's
corresponding field in a table with each selected item seperated by a comma.

Example Listbox:

Item1
Item2
Item3

If the user selectes all 3 items, I want its corresponding field in the
table to show:

Item1,Item2,Item3

Thank you in advance,

-rick
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-rick wrote:
I have a form which contains a multiple selection list box. How can I use
the list box so that all items selected are added to the record of it's
corresponding field in a table with each selected item seperated by a comma.

Example Listbox:

Item1
Item2
Item3

If the user selectes all 3 items, I want its corresponding field in the
table to show:

Item1,Item2,Item3

Thank you in advance,

-rick


You'll have to modify the code to use the proper fields. Plus, I'd look
at any commands, methods, or properties you are unfamiliar with in Help.

Let's say you have 2 columns in the listbox; ID and Description. ID is
column 0, Description is column 1.

Assumption: This is a form and you have 3 fields; item1,item2, item3.

Sub UpdateFromListBox
If Me.YourListBoxName.ItemsSelected.Count > 0 Then
Dim var As Variant
Dim intCnt As Integer
'loop through all items selected
For Each var In Me.YourListBoxName.ItemsSelected
'increment the counter
intCnt = intCnt + 1
'Item + counter = fieldname
'"Item" & 1 = "Item1
'get the data from the second column
Me("Item" & intCnt) = _
Me.YourListBoxName.Column(1, var)
Me.ListYield.Selected(var) = False
Next
ELse
msgbox "No items have been selected."
Endif
End Sub
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.