Hi Rebecca,
I have puzzled over that in the past. Access's query engine does not
seem to be designed to deal with the In/Not In operator when using
parameters. Parameters are designed to provide a single value and what you
are passing to the query is a single string, not a series of strings. So if
you just put the "[Forms]![frm_Form1]![Textbox1]" in the criteria line you
get:
select * from tblYourTable
where Some_Field = [Forms]![frm_Form1]![Textbox1];
which becomes:
select * from tblYourTable
where Some_Field = "In (""A"",""B"",""C"")";
So this compares the value of Some_Field to the actual string "In
(""A"",""B"",""C"")". And if you try using the "In () in the criteria line
instead of the text box:
select * from tblYourTable
where Some_Field In ([Forms]![frm_Form1]![Textbox1]);
this becomes:
select * from tblYourTable
where Some_Field In ("""A"",""B"",""C""");
So this checks to see if the value of Some_Field is in one item,
specifically """A"",""B"",""C""".
Now, you could probably use a whole bunch of fields, where the user
would enter a single item in each text box:
select * from tblYourTable
where Some_Field In ([Forms]![frm_Form1]![Textbox1],
[Forms]![frm_Form1]![Textbox2], [Forms]![frm_Form1]![Textbox3]);
Or, if you want just to allow the user to type in a list of possible
items (leaving off the "In" and the "(" and ")" --i.e.: A,B,C--you could use
the InStr() function:
select * from tblYourTable
where InStr([Forms]![frm_Form1]![Textbox1], Some_Field) > 0;
Which will work as long as Some_Field cannot contain a comma. You
might have to tweak things to deal with that type of situation.
But, what if you want to allow the user to specify the operator and the
criteria? Examples:
1) = "A"
2) In ("A","B","C")
3) Like "*ABC*"
4) Not In ("D","E")
Here is where you can make use of the Eval() function (example of a
text field):
select * from tblYourTable
where Eval("""" & Replace(Some_Field,"""","""""") & """ " &
[Forms]![frm_Form1]![Textbox1]) = True;
Hope this helps,
Clifford Bass
Rebecca_SUNY said:
Access 2003
I have a form that has a text box control. I would like to use the result
of this control as criteria in a simple select query. I have the text box
working correctly and if I copy and paste the result into the query criteria,
it works fine but when I reference the text box control as the criteria it
doesn't work.
text box result = "In ("A","B","C")"
text box control = Forms!frm_Form1!Textbox1
I have also tried this with OR instead of IN but it still doesn't work.