Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing multiple criteria from a Form to a Query

Status
Not open for further replies.

tmryan2

Programmer
Jun 5, 2000
16
CA
I enter text into an unbound control on a form that is referred to in the criteria section of a query. And from this, I can change the criteria of the query each time.<br><br>The name of the control on the form (called Formname) is&nbsp;&nbsp;Controlname. And I refer to this control in the criteria section of the query as: [Forms]![Formname]![Controlname]<br><br>PROBLEM: I can only enter 1 criteria at a time. For example, the query works if I enter &quot;Smith&quot; on the form to find all records with the word &quot;Smith&quot;.<br><br>However, I want to be able to enter multiple criteria on the form such as:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Smith Or Brown&quot;&nbsp;&nbsp;to find two names or <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Smith Or Brow*&quot;&nbsp;&nbsp;have a wildcard in the criteria or <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;&gt;=Smith And &lt;=Zinc&quot; to find a range of names.<br><br>None of the above 3 examples would work and the query would not return any records. It seems as if Access does not evaluate the text first before passing it to the query, so that it literally searches for the text &quot;Smith Or Brown&quot; in the table and not &quot;Smith&quot; or &quot;Brown&quot; as I intended.<br><br>Does anyone have any idea on how to solve this? Any suggestions would be very much appreciated.<br>Thanks in advance.<br><br><br><br>
 
You can add the &quot;LIKE&quot; statement to your query.<br><br>Like [Forms]![Formname]![Controlname] & &quot;*&quot;<br><br>Or try the &quot;Between&quot;<br><br>Between [Forms]![Formname]![Controlname] AND [Forms]![Formname]![Controlname2] <br><br>And also the &quot;OR&quot;<br><br>[Forms]![Formname]![Controlname] OR [Forms]![Formname]![Controlname2] <br><br>on the later two you need to boxes or controls.<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
<br>Thanks very much for your reply DougP. However, the solution you suggest basically hard codes in the number of criteria that a user can enter. What I want to do is to be able to use one control on the form, and enter into it ANY NUMBER of criteria with/without boolean operators. So, I'd like to be able to enter criteria such as:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Smith Or Like *brown or Like Jones*) and &lt;=Zinc<br><br>If I were to enter the above criteria directly into a query, it would be work properly. But if the above were entered into a control on a form and then passed to the query, it wouldn't work because Access wouldn't recognize the words &quot;Or&quot;, &quot;Like&quot;, and &quot;&lt;=&quot; as operators.<br><br>Do you have any thought on this?<br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top