[email protected] wrote:
I have on form frame with 3 options to select report type (All, Top
20, Selected) where Selected reveals ListBox with multi-selection.
There are many options selectable and when combined it will produce
around 7,800 different reports. My goal is to use minimum set of
queries and reports and I will cover with only couple of queries and
reports all cases. Therefore high optimization is required.
Using your solution and for selection from ListBox I have in query:
Expr1: InStr(GetTitles(),[tblTitles].[NameVO])
Criteria: Between (IIf([forms]![frmReport]![frame85]=3,1,0)) And
(IIf([forms]![frmReport]![frame85]=3,1000000,1000000))
"[frame85]=3" indicates that user have selected ListBox option.
Note that I have used workaround - Between 1 and 1000000 or Between 1
and 1000000 and I am not happy with this solution, but at the moment I
don't have any better. Basically this is my question - are there any
better solution?
GetTitles() is sub which determine report type selected and provides
filter to query.
As long as you have a button on the form that open the
report, you can use code instead of going through
contortions in the query.
Use the OpenReport method's WhereCondition argument to
filter the data to the items in the list box, something like
this air code:
Select Case Me.frame85
Case 3
stWhere = "NameVO IN(" & GetTitles() & ")"
DoCmd.OpenReport "report name", acViewPreview, _
WhereCondition:= stWhere
Case 1
DoCmd.OpenReport "report name", acViewPreview
Case 2
DoCmd.OpenReport "report name", acViewPreview, _
OpenArgs:= "XXX"
End Select
To deal with case 2, you will need some code in the report's
Open event. For example:
If Not IsNull(Me.OpenArgs) Then
Me.RecordSource = "your top 20 query name"
End If
You will probably have to tweak the GetTitles function to
use a comma separator and if the NameVO field is a Text
field, add quote delimiters around each item.
Using these techniques to deal with your options, you only
need one copy of the report. You will need two queries,
both of them without any criteria. Just basic Select
queries, one with the TOP 20 and associated ORDER BY clause.