Unanswered: Passing criteria to query and outputting to excel?
I have created a query with no criteria and a report that displays the query. I then wrote code to accept user input via a multiple select list box, which passes the criteria to the query, and open the report. Works great.
What I can't figure out now is how to do the same thing, but output to excel instead of opening a report. I know once the report is open, you can hit the "Analyze with Excel" button on the toolbar, but I want a button on the form to to that automatically. Any ideas? Here is my code fore the report:
Private Function GetCriteria() As String
Dim stDocCriteria As String
Dim VarItm As Variant
For Each VarItm In ListFilter.ItemsSelected
stDocCriteria = stDocCriteria & "[FF] = '" & ListFilter.Column(0, VarItm) & "' OR "
If stDocCriteria <> "" Then
stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
stDocCriteria = "True"
GetCriteria = stDocCriteria
Private Sub previewreport_Click()
DoCmd.OpenReport "rptInventory Detail Current Quarter - Report", acViewPreview, , GetCriteria()