R
Robbro
I've read many of the posts here about using multiple list box selections to
filter queries yet I still cant get it to work. I'll post my understanding
then my code (which I am totally clueless about) and see which is at fault.
My table is called "sales", my query is "sales summary Query", my filter
form is " Filter Report", my listbox is "customerselect" and set to simple
multi select
I then have a hidden control named "customerselect2" with on click set to
event procedure, then in the procedure I've pasted the code from
http://www.mvps.org/access/forms/frm0007.htm
and tried to modify it to my needs as below
Private Sub customerselect2_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Form![Filter Report]
Set ctl = frm!customerselect
strSQL = "Select * from Sales where [Customer]="
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [Customer]="
Next varItem
'Trim the end of strSQL
strSQL=left$(strSQL,len(strSQL)-12))
End Sub
Which I'm sure I've botched in some way.
In my query then I've put "In ([Forms]![Filter Report]![customerselect2])"
in the criteria under customer. When I click my button to run my report its
filtered down to nothing. I should add that I have finally successfully
added filters from this same form for date and plant selection which do
successfully work, so I have the basic process down, the multi-list box thing
is just too complicated so far for me.
Let me know if I need to provide more information.
Thanks
filter queries yet I still cant get it to work. I'll post my understanding
then my code (which I am totally clueless about) and see which is at fault.
My table is called "sales", my query is "sales summary Query", my filter
form is " Filter Report", my listbox is "customerselect" and set to simple
multi select
I then have a hidden control named "customerselect2" with on click set to
event procedure, then in the procedure I've pasted the code from
http://www.mvps.org/access/forms/frm0007.htm
and tried to modify it to my needs as below
Private Sub customerselect2_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Form![Filter Report]
Set ctl = frm!customerselect
strSQL = "Select * from Sales where [Customer]="
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [Customer]="
Next varItem
'Trim the end of strSQL
strSQL=left$(strSQL,len(strSQL)-12))
End Sub
Which I'm sure I've botched in some way.
In my query then I've put "In ([Forms]![Filter Report]![customerselect2])"
in the criteria under customer. When I click my button to run my report its
filtered down to nothing. I should add that I have finally successfully
added filters from this same form for date and plant selection which do
successfully work, so I have the basic process down, the multi-list box thing
is just too complicated so far for me.
Let me know if I need to provide more information.
Thanks