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 » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

'select all' as option in a query?



 
 
Thread Tools Display Modes
  #1  
Old August 7th, 2006, 02:22 PM posted to microsoft.public.access.queries,microsoft.public.access.formscoding
Jerome
external usenet poster
 
Posts: 13
Default 'select all' as option in a query?

My users need a query based on 3 criteria:

Criteria 1: A, B, C or all of them
Criteria 2: A, B, C or all of them
Criteria 3: 1, 2, 3 or all of them

I'v got no problem with the query if distinct values are selected (i.e.
A-C-2), but what's the best way to include the 'all of them' options?

I've made invisible fields on my form and used "*" for the string
criterias and this works, but how to do it with integers?

Thanks a lot!

Jerome
  #2  
Old August 7th, 2006, 03:01 PM posted to microsoft.public.access.queries,microsoft.public.access.formscoding
Allen Browne
external usenet poster
 
Posts: 11,706
Default 'select all' as option in a query?

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

The article has a downloadable sample database that shows you how to build a
Filter string based on the controls where you did enter criteria, and ignore
the boxes where you entered none.

It also explains that the criteria:
Like "*"
does not return all records: those that are null (field left blank) are not
returned.

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

"Jerome" wrote in message
...
My users need a query based on 3 criteria:

Criteria 1: A, B, C or all of them
Criteria 2: A, B, C or all of them
Criteria 3: 1, 2, 3 or all of them

I'v got no problem with the query if distinct values are selected (i.e.
A-C-2), but what's the best way to include the 'all of them' options?

I've made invisible fields on my form and used "*" for the string
criterias and this works, but how to do it with integers?

Thanks a lot!

Jerome



  #3  
Old August 7th, 2006, 03:29 PM posted to microsoft.public.access.formscoding,microsoft.public.access.queries
Kevin McCartney
external usenet poster
 
Posts: 21
Default 'select all' as option in a query?

For any field that are going to have criteria, to remove potential null
fields that wouldn't normally be picked up by a criteria, concatenate a zero
length string at the back e.g. FIELD1 & "" this way for any records that are
null they'll become zero length string and be picked up by the criteria is
the form combox has *, in addition you can put in the your queries criteria
LIKE
IIF(isnull(FORMS!frmNAME!cboNAME.Column(boundolumn )),"*",FORMS!frmNAME!cboNAME.Column(boundolumn)).

HTH
KM

"Allen Browne" wrote:

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

The article has a downloadable sample database that shows you how to build a
Filter string based on the controls where you did enter criteria, and ignore
the boxes where you entered none.

It also explains that the criteria:
Like "*"
does not return all records: those that are null (field left blank) are not
returned.

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

"Jerome" wrote in message
...
My users need a query based on 3 criteria:

Criteria 1: A, B, C or all of them
Criteria 2: A, B, C or all of them
Criteria 3: 1, 2, 3 or all of them

I'v got no problem with the query if distinct values are selected (i.e.
A-C-2), but what's the best way to include the 'all of them' options?

I've made invisible fields on my form and used "*" for the string
criterias and this works, but how to do it with integers?

Thanks a lot!

Jerome




  #4  
Old August 7th, 2006, 03:42 PM posted to microsoft.public.access.formscoding,microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default 'select all' as option in a query?

Kevin, the suggestion might be useful to get someone out of a tight corner,
but it is still less than ideal:

a) The field becomes read-only, so is not suitable for forms where you want
to edit the data.

b) Concatenating a zero-length string turns the field into Text, which
messes up criteria and sorting, and is likely to give problems with numeric
operations on the field (such as summing them.)

c) The approach is inefficient, since Access is unable to use any index on
the field.

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

"Kevin McCartney" wrote in
message
...
For any field that are going to have criteria, to remove potential null
fields that wouldn't normally be picked up by a criteria, concatenate a
zero
length string at the back e.g. FIELD1 & "" this way for any records that
are
null they'll become zero length string and be picked up by the criteria is
the form combox has *, in addition you can put in the your queries
criteria
LIKE
IIF(isnull(FORMS!frmNAME!cboNAME.Column(boundolumn )),"*",FORMS!frmNAME!cboNAME.Column(boundolumn)).

HTH
KM

"Allen Browne" wrote:

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

The article has a downloadable sample database that shows you how to
build a
Filter string based on the controls where you did enter criteria, and
ignore
the boxes where you entered none.

It also explains that the criteria:
Like "*"
does not return all records: those that are null (field left blank) are
not
returned.

"Jerome" wrote in message
...
My users need a query based on 3 criteria:

Criteria 1: A, B, C or all of them
Criteria 2: A, B, C or all of them
Criteria 3: 1, 2, 3 or all of them

I'v got no problem with the query if distinct values are selected (i.e.
A-C-2), but what's the best way to include the 'all of them' options?

I've made invisible fields on my form and used "*" for the string
criterias and this works, but how to do it with integers?



  #5  
Old August 8th, 2006, 07:18 AM posted to microsoft.public.access.queries,microsoft.public.access.formscoding
Jerome
external usenet poster
 
Posts: 13
Default 'select all' as option in a query?

Thanks a lot Allen!

Allen Browne wrote:
Jerome, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

The article has a downloadable sample database that shows you how to build a
Filter string based on the controls where you did enter criteria, and ignore
the boxes where you entered none.

It also explains that the criteria:
Like "*"
does not return all records: those that are null (field left blank) are not
returned.

  #6  
Old August 8th, 2006, 08:22 AM posted to microsoft.public.access.queries,microsoft.public.access.formscoding
Jerome
external usenet poster
 
Posts: 13
Default 'select all' as option in a query? report??

Hi Allen,

I really appreciate your method but I'm wondering if I can really use it
since you're working with filters and I need the query for a report?

How do I integrate your querystring into the SQL query of my report?
Or have I overlooked something?

Thanks a lot,

Jerome

Allen Browne wrote:
Jerome, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

The article has a downloadable sample database that shows you how to build a
Filter string based on the controls where you did enter criteria, and ignore
the boxes where you entered none.

It also explains that the criteria:
Like "*"
does not return all records: those that are null (field left blank) are not
returned.

  #7  
Old August 8th, 2006, 08:33 AM posted to microsoft.public.access.queries,microsoft.public.access.formscoding
Allen Browne
external usenet poster
 
Posts: 11,706
Default 'select all' as option in a query? report??

If the goal is a report, you can create the filter string, and use it as the
WhereCondition for OpenReport.

You leave the criteria out of the query, build the string, and then use it
like this:
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

You won't be able to do that if the fields you are filtering on are not
actually in the report (e.g. if you select records from a period, and
aggregate them, so the report's RecordSource does not have the date field
you wish to filter on.)

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

"Jerome" wrote in message
...

I really appreciate your method but I'm wondering if I can really use it
since you're working with filters and I need the query for a report?

How do I integrate your querystring into the SQL query of my report?
Or have I overlooked something?

Thanks a lot,

Jerome

Allen Browne wrote:
Jerome, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

The article has a downloadable sample database that shows you how to
build a Filter string based on the controls where you did enter criteria,
and ignore the boxes where you entered none.

It also explains that the criteria:
Like "*"
does not return all records: those that are null (field left blank) are
not returned.



  #8  
Old August 8th, 2006, 09:26 AM posted to microsoft.public.access.queries,microsoft.public.access.formscoding
Jerome
external usenet poster
 
Posts: 13
Default 'select all' as option in a query? report??

Thanks, I've now used the SQL query statement that you had presented as
an alternative. It works like a charm (I don't use dates in it) with my
report.

Thanks again!

Allen Browne wrote:
If the goal is a report, you can create the filter string, and use it as the
WhereCondition for OpenReport.

You leave the criteria out of the query, build the string, and then use it
like this:
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

You won't be able to do that if the fields you are filtering on are not
actually in the report (e.g. if you select records from a period, and
aggregate them, so the report's RecordSource does not have the date field
you wish to filter on.)

 




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 01:56 AM.


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