Re: strSQL using Like "*"
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Wed, 13 Aug 2008 23:14:53 +0800
As you found, Like "*" doesn't cut it for nulls. Null doesn't match anything, so you need to craft the WHERE clause so that it does not compare to a field at all.
Switch the query to SQL View, and edit the WHERE clause so it looks like this:
WHERE (([Forms].[Form1].[Combo1] Is Null)
OR ([Field1] = ([Forms].[Form1].[Combo1]))
AND (([Forms].[Form1].[Combo2] Is Null)
OR ([Field2] = ([Forms].[Form1].[Combo2]))
AND ((...
The bracketing is important when you mix ANDs and ORs.
A much more efficient solution is to create the filter string dynamically, in code, from the boxes where the user entered a value. For an example of how to do that, download the sample database from this article:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Steven" <Steven@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BEB34F6A-44ED-4EA2-A3EA-F735F15D51C2@xxxxxxxxxxxxxxxx
I have 5 fields in a table that I want to query using Like "*". And I want
to use a strSQL for the recordset and what I am querying on is based on 5
corresponding texboxes in a form. Now the issue is that I may not be
querying in all the fields for a particular query run...it could be any
combination. ie I might be querying on Field1 and 5 ; or 1 2 3 4 5 ; or 1 3
5 ...etc may combinations. Also I have found in the query that if a field is
null then Like "*" will not return that record.
How can I set up a strSQL that will handle the issue that if for example I
put text in the textbox for Field 1 3 5 that it will know also accept Fields
2 and 4 whatever the value is. I dont want to have to build a string for
every combination of Field possibile combinations. Can it be done in all one
string?
Thank you,
Steven
.
- Follow-Ups:
- Re: strSQL using Like "*"
- From: Steven
- Re: strSQL using Like "*"
- References:
- strSQL using Like "*"
- From: Steven
- strSQL using Like "*"
- Prev by Date: RE: Key Press
- Next by Date: Re: Compact and Repair Alternative
- Previous by thread: strSQL using Like "*"
- Next by thread: Re: strSQL using Like "*"
- Index(es):
Relevant Pages
|
Loading