We help IT Professionals succeed at work.

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

ES-Components
on
68 Views
Last Modified: 2018-09-21
Parameter Query
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?
Comment
Watch Question

President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
ste5anSenior Developer
CERTIFIED EXPERT

Commented:
You must replicate the date range condition in the date column on each condition line where you have another condition on other columns.

Author

Commented:
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!!!

Rick
Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

Commented:
<<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:

Forms![myForm]![myControl]

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.

Jim.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions