I have a report that is linked to a form's List Box. Users can select Product A, Product B, Product C, etc. on the form, and the report will populate with data for the corresponding product.
I'd like to export each version of the report to Excel automatically, and I'm trying to figure out how to use VBA to enter the parameters. Is there a way to cycle through each value in the listbox?
Here's my code so far.
Code:
Sub ExportReport()
Dim ctr As String
Dim BillingTemp As String
Dim qryBilled As DAO.QueryDef
Dim dbs As DAO.Database
Set dbs = CurrentDb
Set qryBilled = dbs.QueryDefs("MyQuery")
'This query is linked to the form with the listbox.
qryBilled.Parameters("Forms!Billing Workbook!listProducts").Value = "Product A"
ctr = Format(Now(), "yyyymmddhhnnss")
ExportPath = CheckExportPath()
BillingTemp = ExportPath & "\BillingTemp_" & ctr & ".xls"
'Fails here. Prompts user to manually enter the parameter.
DoCmd.OutputTo acOutputReport, "BilledPlanned", "Excel97-Excel2003Workbook(*.xls)", BillingTemp, False, "", , acExportQualityPrint
End Sub