Filtering using form field value

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

Guest

I have a query and require to filter it using a value set in a form. (this
part i can do)
however if no value is selected in the field i want the report to show all
records that do not contain a blank/null.

could someone show me an example of the code please for access 2K.

thanks
 
The simplest solution is to omit the criteria from the query.

You probably have a form already where you enter the criteria for the
report. If you add a command button to open the report, you can build the
WhereCondition string so that it filters the report only if the user enters
something, i.e. if there's no criteria, there's no filter, so the report
opens with all records.

There's a simple example of how to filter the report here:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

There's a more comprehensive example of how to create a filter string from
lots of criteria boxes here:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

If you prefer to do it all in the query, switch the query to SQL View (View
menu in query design), and change the WHERE clause to something like this:
WHERE ([Forms].[Form1].[Text0] Is Null)
OR ([MyField] Like [Forms].[Form1].[Text0] & "*")
The condition is True if the text box is null (no entry).
Otherwise the condition matches the field to the value in the text box.
 
Back
Top