How do I retrieve all the items selected from a list box? Note, there may be more than one item selected.
How do I retrieve all the items selected from a list box? Note, there may be more than one item selected.
You have to loop through the items.
Snippet of code from http://www.allenbrowne.com/ser-50.html
Code:<snip> 'Loop through the ItemsSelected in the list box. With Me.lstCategory '<--listbox name For Each varItem In .ItemsSelected If Not IsNull(varItem) Then 'Build up the filter from the bound column (hidden). strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & "," 'Build up the description from the text in the visible column. See note 2. strDescrip = strDescrip & """" & .Column(1, varItem) & """, " End If Next End With <snip>
Thanks, Steve. I'm not an expert, so I don't fully understand the parts that is doing the concatenation. I basically would like to pass the selected values from the list box to a query parameter. I'll pass it using TempVar or function. So, I have a list box with four choices, "Open, to be verified, canceled, completed". If the user chooses "canceled" and "completed", I need to pass the string to the parameter as. How do I achieve that?"canceled" or "completed"
You have a multi-select listbox so you have to loop through the ItemsSelected collection of the list box to generate a string of the selected items.
The snippet of code shows how to loop through the listbox to get the selected items.
This is the best I can do - I know nothing about your dB.