Bonnie,
To begin with there is an error in the code, as a result of which the
leading single quote is truncated at the left of vWhere. If you look at
my original code, the separator in the loop was ", '", i.e. there was a
space between the comma and the single quote; in your code, you omitted
that space, so vWhere = Right(vWhere, Len(vWhere) - 2) truncates the
leading comma and the first single quote, instead of the leading comma
and the first space, as it was intended to.
On top of that, I suspect that the listbox maybe returning a numerical
value, when you expect it to return a description; if there is a numeric
PK field in the table where the listbox gets its rowsource from, it is
quite possible that the wizard has included that field and set it as the
bound column, while making it invisible for the user by setting its
column width to 0. If this is the case, chances are the column count
property of the listbox is set to a value equal to number of visible
columns + 1, while some column's width in the Column widths property is
set to 0; this would most likely be the 1st column; its relative
position should be the same as the value in the listbox's Bound Column
property.
Another way to verify is to add a:
Debug.Print Forms!PickList!List1.ItemData(i)
line somewhere in the loop which constructs the vWhere string, and look
at the values returned in the immediate window when you run the code.
If this is indeed the case (numeric value instead of expected text),
then there are two ways you can go:
(1) change the listbox settings to return the description instead, if
you are certain it is not required to return the numeric PK value in
some other part of your project, or
(2) simply make a slight change in your code to pick up the required
column's value in the listbox, by referencing the proper column; so, to
pick up column 2, for instance (the first shown), the code would be:
vWhere = vWhere & ",'" & Forms!PickList!List1.Column(1,i) & "'"
The used index is for the second column is 1, because the column index
is zero based.
HTH,
Nikos