Sure,
Suppose the listbox has the values of the product ID(ie the rowsource of it contains the ID field and it is also the bound column) - reference: Chance-D2.
First step would be to build a string containing the selected values, from the ItemsSelected collection - reference: PHV:
Code:
Dim strFltr As String
Dim itmItem
'Make sure there is something selected
If Me("ListBoxName").ItemsSelected.Count>0 Then
For Each itmItem in Me("ListBoxName").ItemsSelected
strFltr=strFltr & Me("ListBoxName").ItemData(itmItem) & ","
Next
strFltr="[IDFieldName] In(" & Left(strFltr,Len(strFltr)-1) & ")"
End If
'The result should look like: [IDFieldName] In(7,22,1975)
Now, there may be 2 choices:
1. The report is based on a query that
contains the corresponding ProductID field, either the PK from the Products table or the FK from a related table. I'm almost sure this is the case.
Then:
Code:
DoCmd.OpenReport "ReportName", acViewPreview, , strFltr
Note that if there is no selection made in the listbox, this will open the report for ALL records
[/code]
2. The report is based on a groups/totals query that
does NOT contain the ProductID field.
This is a little more complicated, because the basic structure of SQL requires the Where clause to be defined BEFORE the Group By clause:
Select Field1, Field2
From TableName
Where 1=1
Group By Field1, Field2
Having Field1=25;
Therefore, you need to 'inject' the Where Clause into the SQL definition, and in this case I would like to find out if you use a query (and what's its SQL) or directly an SQL statement as recordsource of the report.
It would be also nice to know what Access version you use.
In any case, user filtering should be client-side built and processed, this way any user will be independant from others.
SQL Server provides the notion of 'temporary tables', but there is no such thing in Access.
HTH
![[pipe] [pipe] [pipe]](/data/assets/smilies/pipe.gif)
Daniel Vlas
Systems Consultant