On a form I have a multi select list box. I want to use the records selected as a filter in a query.
I thought that I would create an unbound control (strProductsSelected) on the form and populate it with the records selected like this:
If for example 3 records were selected, strProductsSelected would look something like this: 838 or 905 or 56
and then use a query like this:
SELECT ProductId, ProductCode, ProductDescription FROM tblProduct
WHERE (((tblProduct.ProductId)=[Forms]![frmPrintProductSelected]![strProductsSelected]));
But when I run the query no records are returned!
What am I doing wrong?
Is my method the most efficient?
How many ProductId's can be included in strProductsSelected am I limited to 256 characters?
Thanks in advance
I thought that I would create an unbound control (strProductsSelected) on the form and populate it with the records selected like this:
Code:
Me.strProductsSelected = ""
If Me.lstSelectProduct.ItemsSelected.Count = 0 Then Exit Sub
For Each varItem In Me.lstSelectProduct.ItemsSelected
Me.strProductsSelected = Me.strProductsSelected & Me.lstSelectProduct.Column(0, varItem) & " or "
Next
Me.strProductsSelected = Left(Me.strProductsSelected, Len(Me.strProductsSelected) - 4)
and then use a query like this:
SELECT ProductId, ProductCode, ProductDescription FROM tblProduct
WHERE (((tblProduct.ProductId)=[Forms]![frmPrintProductSelected]![strProductsSelected]));
But when I run the query no records are returned!
What am I doing wrong?
Is my method the most efficient?
How many ProductId's can be included in strProductsSelected am I limited to 256 characters?
Thanks in advance