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
4 1969
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: -
-
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere & "AND" & strWhere2, OpenArgs:=strDescrip
-
-
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
NeoPa 32,556
Expert Mod 16PB
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: -
-
DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere & "AND" & strWhere2, OpenArgs:=strDescrip
-
-
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
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 : - ...IIf(A="asdf"AndB="",1,0)...
This will fail whereas the intended version (using " And ") would work : - ...IIf(A="asdf" And B="",1,0)...
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |