473,406 Members | 2,208 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,406 software developers and data experts.

using two multiselect boxes to filter a report

Hello,

Does anyone know what to alter this VBA code (below) so that a report can be filtered using criteria from TWO multiselect boxes? e.g. allowing the user to view products from multiple categories and multiple prices within those categories.

http://allenbrowne.com/ser-50.html




Thanks,
Laura
May 14 '08 #1
4 1969
patjones
931 Expert 512MB
As a first approximation, I'd say this...

If you look at the two sections of code commented "Loop through the ItemsSelected in the list box" and "Remove trailing comma. Add field name, IN operator, and brackets" - I would probably add another string variable, call it "strWhere2" - and duplicate those two sections of code for the second multi select box, but using strWhere2.

Once strWhere2 is built up, you could then try something like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere & "AND" & strWhere2, OpenArgs:=strDescrip
  3.  
  4.  
The WhereCondition argument has to look like a SQL WHERE test, so that's why I'd try using the AND to connect strWhere and strWhere2 to form the whole criteria...

Pat
May 15 '08 #2
NeoPa
32,556 Expert Mod 16PB
Would Example Filtering on a Form help you?
May 16 '08 #3
Fabulous!

I just had to add "OpenArgs:=strDescrip & "And" & strDescrip2" as well and it worked great!

THANKS!!


As a first approximation, I'd say this...

If you look at the two sections of code commented "Loop through the ItemsSelected in the list box" and "Remove trailing comma. Add field name, IN operator, and brackets" - I would probably add another string variable, call it "strWhere2" - and duplicate those two sections of code for the second multi select box, but using strWhere2.

Once strWhere2 is built up, you could then try something like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere & "AND" & strWhere2, OpenArgs:=strDescrip
  3.  
  4.  
The WhereCondition argument has to look like a SQL WHERE test, so that's why I'd try using the AND to connect strWhere and strWhere2 to form the whole criteria...

Pat
May 20 '08 #4
NeoPa
32,556 Expert Mod 16PB
You're probably fine in your case if it's working, but remember the the word "And" typically requires spaces around it to avoid confusion.

Consider the resulting SQL in this case if the "And" is not surrounded by spaces :
Expand|Select|Wrap|Line Numbers
  1. ...IIf(A="asdf"AndB="",1,0)...
This will fail whereas the intended version (using " And ") would work :
Expand|Select|Wrap|Line Numbers
  1. ...IIf(A="asdf" And B="",1,0)...
May 21 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: amywolfie | last post by:
Hi All: I would like to run a report based on criteria from 3 unbound combo boxes located on a parameter form (combo boxes are: cboCuisine, cboLocation, and cboRestaurant) The present code...
2
by: seansan | last post by:
Hi, suppose I have one report that reports some data to me based on a functional area that I define. We have about 20 func_areas and every time the report is the same. Is there some way to have...
1
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
2
by: Cassie Pennington | last post by:
I am trying to write various items from a multiselect list box to an SQL statement to update a report, without success. SQL only appears to accept hard-coded data or control values from a form, not...
3
by: Afton | last post by:
I would like to make a form that filters a report by Supervisor and by starting and ending date. I have the supervisors in a combo box, and that works. However, I do not know how to code to let...
1
by: Jillian Cee | last post by:
I have a multiselect list box (simple). I need to find out how to get Access to recognise my multiple selections firstly (I believe) then I want these selections to go into a query so that I can...
6
by: fieldja | last post by:
I have a form called OwnerForm. It contains a combo box called Owner. The combo box looks up names from a table called OwnerName. It contains fields called OwnerID and Owner. I also have a main...
1
by: Cara Murphy | last post by:
Hi There! Hoping you are able to help me with a filtering scenario: I have created a pop up form (Filter) to filter a report (Open Issues), which currently has a number of combo boxes which...
2
by: hollinshead | last post by:
hi there, i have been having this issue for quite some time now and i cant seem to get my head around it. I am trying to create a database for candidates CV's and covering letters. basically the data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.