I've recently done this myself for a report based on a union query that references about 8 different tables from 7 different filter boxes. I used combo boxes as opposed to list boxes, but I'll talk you through what I did as I don't seem why listboxes would be a problem:
Firstly, how have you added in the All option? Have you added it as another value in the table, or just added it to the filter using SQL?
I found the SQL route is tidier because the all option was only needed to indicate 'no filter', and not an actual value in the table, so for the rowsource of each filter listbox, you're going to want something along the lines of:
- SELECT DISTINCT TableName.FieldName FROM TableName UNION SELECT '(All)' FROM TableName
-
ORDER BY TableName.FieldName;
(Putting brackets around All defaults it to the top of the list)
After I did that for each filter box, the report recordsource can be based on a query like this:
- SELECT TableName.Field1, TableName.Field2, TableName.Field3
-
FROM TableName
-
WHERE (((TableName.Field1=Forms! FilterForm!Filter1 Or Forms! FilterForm!Filter1 ="(All)")=True) And ((TableName.Field2=Forms!FilterForm!Filter2 Or Forms! FilterForm!Filter2="(All)")=True) And ((TableName.Field3=Forms! FilterForm!Filter3 Or Forms! FilterForm!Filter3 Is Null)=True))
-
ORDER BY Whatever;
-
This example treats Field1 and Field2 as strings, and Field3 as an integer.
As you've probably noticed, there is slightly different coding for field3 - this is because integer fields have a slight problem with the '(All)' value - because '(All)' is a string, when you try and run the report it errors as a type mismatch. I don't know whether changing the field to type Variant would solve this, but to get round it, on the "load report" button on the filter form, I added some code before it opened the report:
- If Me.IntegerField.Value = "(All)" Then
-
Me.IntegerField.Value = Null
-
End If
-
DoCmd.OpenReport "ReportName", acViewReport
This will allow you to create an entire query to base the report on, with only a very small amount of programming required to handle integers (maybe not even required if Variant works)
It might not be the perfect solution, but it's one I've found to work well.
Hope that helps.
Adam.