Create a function that looks something like:
Public Function fnMultiListSelections(lst as listbox) as Variant
Dim varItem As Variant
Dim varValue As Variant
varValue = Null
For Each varItem In Me.List0.ItemsSelected
varValue = (varValue + ", ") _
& Me.List0.Column(Me.List0.BoundColumn - 1, varItem)
Next
fnMultiListSelections = varValue
End Sub
If the bound column is textual, then you will need to wrap the value in
quotes, similar to:
varValue = (varValue + ", ") _
& chr$(34) _
& Me.List0.Column(Me.List0.BoundColumn - 1, varItem) _
& chr$(34)
Then, in a command buttons click event or something event, you can call the
function like:
strSQL = "SELECT * FROM yourTable " _
& (" WHERE [SomeField] IN(" _
+ fnMultiListSelections(me.lst_ControlName) _
+ ")" )
The second part of the above line of code (the part wrapped in parenthesis)
will create the WHERE clause if the function returns some values, but will
leave it off if the function returns a NULL (no items selected).
Another way to handle this (I actually prefer it actually) is to include an
IsSelected (Yes/No) field in the table that is the source for your listbox.
Then, in the click event of the listbox, I update the IsSelected property of
that record. Then, I can simply write a query that joins the table to
another table and add a WHERE clause similar to:
WHERE tbl_ListSource.IsSelected <> 0
This method requires constantly updating the underlying table when items are
clicked in the listbox, but the subsequent query will generally run quicker,
since using the IN( ) clause can be slow.
--
HTH
Dale
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
SC in Texas said:
How do I get the selected values that are chosen in a list box into the where
statement for a report to use?
Thanks in advance,
SC in Texas