A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Search Form, # of Records



 
 
Thread Tools Display Modes
  #1  
Old December 14th, 2006, 10:35 PM posted to microsoft.public.access.forms
sunshineleo
external usenet poster
 
Posts: 31
Default Search Form, # of Records

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!

  #2  
Old December 15th, 2006, 03:26 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Search Form, # of Records

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

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



  #3  
Old December 15th, 2006, 05:55 AM posted to microsoft.public.access.forms
sunshineleo
external usenet poster
 
Posts: 31
Default Search Form, # of Records

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

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




  #4  
Old December 15th, 2006, 05:59 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Search Form, # of Records

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!



  #5  
Old December 15th, 2006, 07: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!




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.