View Single Post
  #5  
Old December 15th, 2006, 06:53 AM posted to microsoft.public.access.forms
sunshineleo
external usenet poster
 
Posts: 31
Default Search Form, # of Records

Thanks Allen... as always, you are a great help!

"Allen Browne" wrote:

Yes, the code needs a different:
If IsNull(...
block for each criterion.

The VBA code doesn't go in the query though.

--
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.

"sunshineleo" wrote in message
...
Thanks for your reply!

I would have to put a separate statement for each field that can be
included in the query, yes?
So, Instead of this:

If IsNull(Me.cbo_EntityCountry.Value) Then
strcountry = " Like '*' "
Else
strcountry = "='" & Me.cbo_EntityCountry.Value & "' "
End If

I would now use this:
If Not IsNull(Me.cbo_EntityCountry) Then
strWhere = strWhere & "([Country] = """ & Me.txtFilterCountry &
""")
AND "
End If

"Allen Browne" wrote:

You are probably right about the nulls.

Typically people put this kind of thing in their query:
Like [Forms].[Form1].[Combo2] & "*"
However, that criterion does NOT return the records where the field is
null.

It is possible to write the WHERE clause of the query so the criterion is
True if the combo is null, e.g.:
WHERE (([Forms].[Form1].[Combo2] Is Null)
OR ([MyField] Like [Forms].[Form1].[Combo2] & "*"))
AND ...
You can probably see this gets very convoluted if you have lots of
criteria.

A much more efficient solution is to leave the criteria out of the query,
and build the it as a string using only the boxes where the user entered
something. You can then apply it as the WhereCondition for OpenReport,
the
Filter of your form, or even as the SQL property of a QueryDef.

For an example, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html


"sunshineleo" wrote in message
...
I have a search form with combo boxes.... I don't understand why if
there
are
700 records, only 620 show up in the query results when nothing is
selected.
I think it may be because some of the fields included in the search
have
nothing in the field, or they are Null. How do I overwrite this?
Thanks for the help!