Using textbox on form as query criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with five simple multiselect listboxes from which I want to run
a query and ultimately print a report. I have a hidden textbox for each of
the listboxes to which I refer to in the query criteria for the approriate
field. The reference works fine if only one value is selected from the
listbox, but I get an error if more than one value is selected. I have used
VBA to get the textbox to report each of the following, but I have the same
problem if more than one value is selected:

Attempt #1:
txtlinear: (when more than one value selected from the list box)
30 , 40
query criteria: In( [Forms]![GrowerSearchF]![txtlinear])

Attempt #2:
30 Or 40
query criteria: [Forms]![GrowerSearchF]![txtlinear]

Attempt #3:
Select * from Linear where [Linear]=30 OR [Linear]=40
query criteria: [Forms]![GrowerSearchF]![txtlinear]

Error message:
This expression is typed incorrectly, or it is too complex to be evaluated.
For example, a numeric expression may contain too many complicated elements.
Try simplifying the expression by assigning parts of the expression to
variables. (Error 3071)

Again, the reference works fine when the text box reports only one value
selected, ie:
30
30
Select * from Linear where [Linear]=30

Please help before I beat my head against the computer screen.
Thanks, Jess
 
The simple answer is you cannot use a reference to a field in a form for more
than 1 criteria. If you need more than 1 you need to build the sql string in
code. I usaully build it using query design then paste it into my VBA code.
Then add depending on the selection the Where [linear]=30 or [linear]=40...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top