Joe:
I assume that you are either entering the asterisk in a control on a
form which the query references as a parameter along the lines of
Forms!YourForm!YourControl or in a system generated parameter prompt
such as [Enter a value or * for all records]. in which case the
criterion would be the parameter not a literal asterisk character:
Like Forms!YourForm!YourControl
However a better way to 'optionalize' the parameter is to test for OR
IS NULL. The parameter, whether its a control on a form or a simple
parameter generating a prompt would then be left blank (Null) rather
than defaulting to an asterisk, and the criterion for the actual
column in the query (not a computed column using the Nz function)
would be like this:
Forms!YourForm!YourControl OR Forms!YourForm!YourControl IS NULL
In SQL this would be a parenthesised expression in the WHERE clause:
([YourField] = Forms!YourForm!YourControl OR Forms!YourForm!
YourControl IS NULL)
If you enter this expression in the columns' criteria row in query
design view and then save the query, if you then open it again in
query design view you'll find that Access has moved things around.
The underlying logic will be the same, but you might find it difficult
making any further amendments to the query in design view. Its
generally better with a query with a complex WHERE clause to write
and save it in SQL.
Ken Sheridan
Stafford, England
Ken,
I followed your instructions but when entering * for all the criteria
parameters only the rows with the non-null fields are returned. Am I missing
something?
Thanks,
Joe M.
There's no need to add an extra column; simply use:
WHERE NZ([YourColumn],"") LIKE "*"
To do this in query design view enter NZ([YourColumn],"") in the
'field' row of a blank column in the grid, uncheck the 'show' check
box and enter LIKE "*" in the 'criteria' row, substituting the real
column name of course.
Ken Sheridan
Stafford, England