Solved How to filter using multiple criteria from the list

Fitzi

New member
Local time
Today, 21:57
Joined
Oct 20, 2022
Messages
6
Hello,
I have this example where I use Combo Box to filter the subform and the charts.
I want to do the same thing using list box, but I couldn't make the links!

I want to be able to filter according to several criteria from a list at the same time.

Also, depending on what I selected in the first lboClient list, only the specifics for the project should appear in the second list lboProiect just like in combo box.

attached database,
Thanks in advance for your help!
 

Attachments

use a continuous form to show all records,
then when the user fills in the boxes, then clicks the FIND button, use vb to build the where clause:

Code:
sub btnFind_click()
dim sWhere as string

sWhere = "1=1"
if not IsNull(txtBox1) then sWhere = sWhere & " and [field1]='" & me.txtBox1 & "'"    'string
if not IsNull(txtID) then sWhere = sWhere & " and [ID]=" & me.txtID              'numeric
if not IsNull(cboBox) then sWhere = sWhere & " and [field3]='" & me.cboBox & "'"

if sWhere = "1=1" then
   me.filterOn = false
else
   me.filter = sWhere
   me.filterOn = true
endif
 
use a continuous form to show all records,
then when the user fills in the boxes, then clicks the FIND button, use vb to build the where clause:

Code:
sub btnFind_click()
dim sWhere as string

sWhere = "1=1"
if not IsNull(txtBox1) then sWhere = sWhere & " and [field1]='" & me.txtBox1 & "'"    'string
if not IsNull(txtID) then sWhere = sWhere & " and [ID]=" & me.txtID              'numeric
if not IsNull(cboBox) then sWhere = sWhere & " and [field3]='" & me.cboBox & "'"

if sWhere = "1=1" then
   me.filterOn = false
else
   me.filter = sWhere
   me.filterOn = true
endif
Thanks for your reply.
I don't want to use Combo box anymore, I want to be able to filter data only through listbox.
To be able to select several criteria at the same time, in the combo box I can only select one criterion
Anyway, I'm not an expert in VBA, I'm a beginner..I can't quite match the code with what I need, if you could update this part in the attached file, it would be a great help
 
IMHO you should start again with your db.
It needs to be normalized. You have only one table with about 200 fields.

I would also recommend you that you avoid using spaces in the Name given to any object in the database and that you adopt a naming convention throughout.
 
check and test your listbox.
 

Attachments

check and test your listbox.
Thank you very much for your help!!!
It works the way I wanted it to work.
If it's not too much trouble, if you could also help me with the second list...depending on what I select in the first list, only the respective projects should appear in the second list.
When I select a client from the first list, it should show me projects only from that client, And also to be able to filter using both lists.
If it's not too much trouble..

Thanks again for your help, I appreciate your help and time for this!
 
here test it again.
 

Attachments

Users who are viewing this thread

Back
Top Bottom