Solved How to filter using multiple criteria from the list (1 Viewer)

Fitzi

New member
Local time
Today, 21:23
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

  • graf.accdb
    1.7 MB · Views: 222

Ranman256

Well-known member
Local time
Today, 14:23
Joined
Apr 9, 2015
Messages
4,337
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
 

Fitzi

New member
Local time
Today, 21:23
Joined
Oct 20, 2022
Messages
6
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
 

bob fitz

AWF VIP
Local time
Today, 19:23
Joined
May 23, 2011
Messages
4,727
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:23
Joined
May 7, 2009
Messages
19,247
check and test your listbox.
 

Attachments

  • graf.accdb
    980 KB · Views: 95

Fitzi

New member
Local time
Today, 21:23
Joined
Oct 20, 2022
Messages
6
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!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:23
Joined
May 7, 2009
Messages
19,247
here test it again.
 

Attachments

  • graf.accdb
    984 KB · Views: 147

Users who are viewing this thread

Top Bottom