ACC: Showing All Records (Including Null) in a Parameter QueryID: Q103181
|
Moderate: Requires basic macro, coding, and interoperability skills.
When you run a query that takes its parameters from a form, no
records are returned by the query if you leave the field blank. If you
type an asterisk (*) in the field, only records with non-Null values
are returned.
This article describes a method you can use to return all records,
including those with Null values, when you leave the parameter blank.
NOTE: A demonstration of the technique used in this article can be seen
in the sample file, Qrysmp97.exe. For information about how to obtain
this sample file, please see the following article in the Microsoft
Knowledge Base:
Q182568 ACC97: Microsoft Access 97 Sample Queries Available on
MSL
The following example is based on the sample database Northwind.mdb
(or NWIND.MDB in Microsoft Access 2.0 or earlier).
Form: Pick Employees
--------------------
Control: Textbox
ControlName: Region
Control: Command Button
Caption: Run Query
OnClick: Run Employee Query
Macro Name Action
------------------------------
Run Employee Query OpenQuery
Run Employee Query Actions
--------------------------
OpenQuery:
Query Name: Employee Query
View: Datasheet
Data Mode: Edit
Query: Employee Query
---------------------
Field: First Name
Show: True
Field: Last Name
Show: True
Field: Region
Show: True
Criteria: Like Forms![Pick Employees]!Region & "*"
Or: <leave blank>
Field: Forms![Pick Employees]!Region
Show: False
Criteria: <leave blank>
Or: Is Null
Where Region Like Forms![Pick Employees]!Region & "*"
Or Forms![Pick Employees]!Region Is Null
For more information about this topic, search the Help Index for "like operator," or ask the Microsoft Access 97 Office Assistant.
Additional query words: queries
Keywords : QryParm
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 26, 1999