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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting 2 conditions on a Form to Open a Report.......

Status
Not open for further replies.

Benj

Programmer
Nov 30, 1999
7
GB
I have created a form with 2 combo boxes. One Combo-box containing makes and one containing prices.<br>
I have then put a button on the form that prompts to open a report depending upon what data is chosen from the combo-box.<br>
It runs OK if either combo-box is set to find &quot;*ALL&quot;, but if for example I search for &quot;Watches&quot; and less than &quot;£500&quot; it cannot handle this.<br>
<br>
I have used the code:<br>
<br>
DoCmd.OpenReport [Reprtname], acViewPreview, , (&quot;[Make]='&quot; & [Forms]![Formname]![Make] & &quot;'&quot;) And (&quot;[Price]&lt;&quot; & [Forms]![Formname]![Price])<br>
<br>
It doesn't seem to like the And function that I have used in the coding. Is there a differnet way of coding this??<br>
<br>
Thanks, <p>Ben Smith<br><a href=mailto:Ben.Smith@nswl-tr.nwest.nhs.uk>Ben.Smith@nswl-tr.nwest.nhs.uk</a><br><a href= > </a><br>
 
Hi Benj<br>
<br>
The And needs to be inside the quotes.<br>
<br>
Your whereclause should read:<br>
<br>
&quot;[Make]='&quot; & [Forms]![Formname]![Make] & &quot;' And [Price]&lt;&quot; & [Forms]![Formname]![Price])<br>
<br>
<br>
To make it crystal clear to yourself, why not assign the whereclause to a string variable which gets set right before the openreport command. Then you can put a stop on the OpenReport line and take a look at the whereclause in the immediate window. That way you can make sure that it's formed just as it should be.<br>
<br>
<br>
Good luck.<br>
<br>
Rochelle<br>
<br>

 
Another way of doing this is to set the parameters at the query level instead of doing it through the DoCmd.OpenReport. <br>
<br>
You can add the parameter [Forms]![FormName]![Make] in the Make column in the query and [Forms]![FormName]![Price] in the Price column. Therefore, whatever changes you make in the combo boxes once the report is opened from the form the query will reflect the change.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top