473,414 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Filter Report on multiple selections in a list box

I can filter a query for a report on a field of a subform BUT now....
I'd like to be able to select more than one item in a multi-list box
to select all the records.

ALSO
to use two fields (or more) fields to filter a query based on
selections in two or more fields:

All the records with NAME = all the names selected in a list box
BETWEEN StartDate and EndDate

HELPPP please.

-warning e-mail address altered- arthureNOSPACE@
Nov 12 '05 #1
3 18177
If possible, use the WhereCondition of the OpenReport action instead of
filtering in the query.

This assumes you have a form that contains the listbox and textboxes used
for filtering. The form will have a command button to open the report. The
OpenReport action has a WhereCondition. Build up a string consisting of the
values you wish to filter by, and then use that as the WhereCondition of the
OpenReport action.

To create the string from the items in a multi-select list box, your code
will need to loop through the ItemsSelected collection of the list box. Use
ItemData. Remember to include the quote delimiters if the field being
filtered is of type Text (not Number). After concatenating the items
together, use the IN operator. The resultant string will be something like
this:
"[Surname] IN (""Jones"", ""Smith"", ""O'Brien"")"

For multiple conditions, include an AND in the WhereCondition string.

For an example of how to work with a start date and end date, see:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"arthur-e" <ar*****@ix.netcom.com> wrote in message
news:du********************************@4ax.com...
I can filter a query for a report on a field of a subform BUT now....
I'd like to be able to select more than one item in a multi-list box
to select all the records.

ALSO
to use two fields (or more) fields to filter a query based on
selections in two or more fields:

All the records with NAME = all the names selected in a list box
BETWEEN StartDate and EndDate

Nov 12 '05 #2
Thanks, Allen - yes, I'd like to use the WhereCondition not really a
filter - but I always have trouble with the syntax -
I thought the WhereCondition would be a concantenation with "OR"
between the selected items.

Do you know of an example somewhere on the web I could look at?

Arthur

"Allen Browne" <ab***************@bigpond.net.au> wrote:
If possible, use the WhereCondition of the OpenReport action instead of
filtering in the query.

This assumes you have a form that contains the listbox and textboxes used
for filtering. The form will have a command button to open the report. The
OpenReport action has a WhereCondition. Build up a string consisting of the
values you wish to filter by, and then use that as the WhereCondition of the
OpenReport action.

To create the string from the items in a multi-select list box, your code
will need to loop through the ItemsSelected collection of the list box. Use
ItemData. Remember to include the quote delimiters if the field being
filtered is of type Text (not Number). After concatenating the items
together, use the IN operator. The resultant string will be something like
this:
"[Surname] IN (""Jones"", ""Smith"", ""O'Brien"")"

For multiple conditions, include an AND in the WhereCondition string.

For an example of how to work with a start date and end date, see:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

-warning e-mail address altered- arthureNOSPACE@
Nov 12 '05 #3
If you use the OR operator, all the records that are named in the list box
will be included. Any records between the dates will also be included
(regardless of whether they match the listbox), since they only have to met
one condition or the other.

If you use the AND operator, only the records that are named in the list box
and also fall in the date range will be returned.

The basic idea for looping through the items of the list box is this:

Dim vItem As Variant
Dim lngLen as Long

With Me.MyListbox
For Each vItem In .ItemsSelected
If Not IsNull(vItem) Then
strWhere = strWhere & """" & .ItemData(vItem) & """, "
End If
Next
End With
lngLen = Len(strWhere) - 2 'Without trailing comma and space.
If lngLen > 0 Then
strWhere = "[MyField] IN (" & Left$(strWhere, lngLen) & ")"
End If
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"arthur-e" <ar*****@ix.netcom.com> wrote in message
news:7j********************************@4ax.com...
Thanks, Allen - yes, I'd like to use the WhereCondition not really a
filter - but I always have trouble with the syntax -
I thought the WhereCondition would be a concantenation with "OR"
between the selected items.

Do you know of an example somewhere on the web I could look at?

Arthur

"Allen Browne" <ab***************@bigpond.net.au> wrote:
If possible, use the WhereCondition of the OpenReport action instead of
filtering in the query.

This assumes you have a form that contains the listbox and textboxes used
for filtering. The form will have a command button to open the report. TheOpenReport action has a WhereCondition. Build up a string consisting of thevalues you wish to filter by, and then use that as the WhereCondition of theOpenReport action.

To create the string from the items in a multi-select list box, your code
will need to loop through the ItemsSelected collection of the list box. UseItemData. Remember to include the quote delimiters if the field being
filtered is of type Text (not Number). After concatenating the items
together, use the IN operator. The resultant string will be something likethis:
"[Surname] IN (""Jones"", ""Smith"", ""O'Brien"")"

For multiple conditions, include an AND in the WhereCondition string.

For an example of how to work with a start date and end date, see:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

-warning e-mail address altered- arthureNOSPACE@

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Craig B. | last post by:
I am relativly new to access 2000 and am having some trouble with a report. I am not sure what I want to do is something I can do in access. I want to be able to choose from a combo box multiple...
11
by: Bob | last post by:
I am in the process of upgrading an Access database to SQL Server (and climbing that learning curve!). The wizard happily upgraded all the tables and I can link to them OK using ODBC. The...
6
by: pobnospam | last post by:
I have a field called ingredients where multiple ingredients can be contained in one record (client request). Now when a report is run I need to prompt a user to determine which records to display...
1
by: Belebala | last post by:
I have the code for filtering report on multiple selections in a list box, but how do I modify the following code to use "like" operator instead of "in". I tried to replace: strWhere = " LIKE ('*"...
2
by: Thall | last post by:
Hey Gurus - I've seen a few solutions to this problem, but none of which I can do without a little help. Here's the situation The following code loops thru a sales report, using the sales rep ID...
3
by: josejomonm | last post by:
I am having a list box where I will select the Plants (Plant-1 or Plant-2 Etc.) or leave blank for selecting all plants. Another list box in the same form where the supervisors list is provided. A...
4
by: Fran | last post by:
I recently tried to use code for "Use a multi-select list box to filter a report" from Allen Browne in my database. I was able to add the code and adapt it to my needs, however I am getting an...
0
by: Germaris | last post by:
Hi there! Is it possible to make multiple selections in a ComboBox ? i.e. make n consecutive selections and store them in an array or make n selections in the open list of the CB by using (for...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.