Link to home
Start Free TrialLog in
Avatar of ES-Components
ES-ComponentsFlag for United States of America

asked on

Why doesn't the Parameter Query work with the input from the Access Form?

User generated image
Please see Embed FIle for snapshot of a Parameter Access Query. I have a form that supplies the input to this query.
All the fields on the Form ARE NOT required to be filled in except the Date Range. The other fields on the form are
Filtered fields. If the user Does NOT select any filter field but just selects the Date Range, the design of the Parameter Query works.
If the user selects the Date Range and filters any of the other fields, the Parameter Query does not work correctly.
Is the parameter query not the best way to return the correct information based on what the user does on the form?

I am not a programmer. Is there a better way to do this?
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You must replicate the date range condition in the date column on each condition line where you have another condition on other columns.
Avatar of ES-Components


Thank you both for your quick response and help. The "Is Null" part was what what I needed to understand better.
Thank you both for giving me the examples.
The Form works perfect now and we are able to Print, Send Email, and Export the results of the Form Filters!!!

<<I am not a programmer. Is there a better way to do this?>>

Just one additional comment; the answer to that question was yes, but you need to be a programmer to use it, so for the present, stick with the method you have.

But to further your understanding a bit, when you work with a query, what your really working with is an SQL statement:

  SELECT   <field>  FROM  <table>  WHERE <criteria>

 This is what all relational database systems work with under the covers.   You can see this SQL when your in the query designer by selecting "SQL View".

 Right now, Access is doing the checks of what is and is not filled in by you including the "IS NULL".     It's also having to grab the values from the form controls.

  But it would be more efficient if those checks were only included if something was filled in and you got the specific value.

  With code, you can build up an SQL statement "on the fly" and then execute it.  That would look something like this:

  strSQLWhere = ""

  If NZ(Forms![myForm]![myControl],"")<>"" then
      strSQLWhere = strSQLWhere " AND " [Field] = " & Forms![myForm]![myControl]
  End If

So were saying if something is in the control, add it to the string variable strSQLWhere, and you'd repeat that for each condition.   In the end, you have a very efficient SQL statement to execute.

  But the method your using now is fine and will get the job done.  The only hassle is that Access reformat's the query.   You'll notice if you open it again that Access has placed all the control references in a column:


with a multitude of IS NULL checks below it.    Note that criteria grid has gotten really complicated to follow.

So the downside for a query like this is that if you need to modify it,  it's best to erase those columns on the end, all the criteria, and start again with the criteria.  Otherwise you'll spend a lot of time trying to get all those checks right.