Omitting the OR operation will be fine if (a) the dialogue form contains only
one control in which to enter or select a parameter value, or (b) it contains
multiple parameter controls and values are being inserted into all of them.
The purpose of testing for OR IS NULL is that it makes a parameter optional.
Say you have just two parameter controls txtCity and txtLName then the WHERE
clause of a query would be like this:
WHERE (City = Forms!frmSearch!txtCity
OR = Forms!frmSearch!txtCity IS NULL)
AND (LName = Forms!frmSearch!txtLName
OR = Forms!frmSearch!txtLName IS NULL)
If a value is entered in txtCity then the first part of the parenthesised
expression (City = Forms!frmSearch!txtCity OR = Forms!frmSearch!txtCity IS
NULL) will evaluate to TRUE for any row containing the value in the City
column. As the expression uses a Boolean OR the whole parenthesised
expression will consequently evaluate to TRUE. If LName is left blank
(NULL), then the second parenthesised expression (LName =
Forms!frmSearch!txtLName OR = Forms!frmSearch!txtLName IS NULL) will also
evaluate to TRUE for all rows as the second part of the expression will
evaluate to TRUE for any row in the table. Consequently the WHERE clause as
a whole evaluates to TRUE for any row with the value in the City column,
regardless of what's in the LName column.
If the OR IS NULL operations are omitted then each expression must evaluate
to TRUE for a row to be returned, i.e. the values in the City and LName
columns must both match those entered in the form, and neither control can be
left blank.
Unfortunately, if you enter the criteria in query design view rather than in
SQL view Access moves things around quite a lot, making the underlying logic
of the WHERE clause far less easy to see. I'd always write and save a query
like this in SQL for this reason.
To clear the controls you don't use Me.Controls = Null, you loop through the
form's Controls collection setting each control to Null, ignoring the error
which is raised if a control is a type which cannot be set to Null:
On Error Resume Next
For Each ctrl in Me.Controls
ctrl = Null
Next ctrl
Ken Sheridan
Stafford, England