I produce monthly invoices for a club. I use a query to produce the invoices. I run a procedure from a form, a dataset is opened and the reports are posted a pdfs. At present I write the month criteria in the query and this works OK. I am now trying to use a combo box in the usual way on the form to pass the parameter to the query. When I run the query from the form but when I run the procedure I get the following Error Message
This is the code
Private Sub cmdPrintNew_Click()
Dim rs As DAO.Recordset
Dim strSql As String
Dim cMth As String
Dim cName As String
Dim nEbu As Single
Dim filename As String
Dim filepath As String
Set rsInvoices = CurrentDb.OpenRecordset("Invoice Query")
rsInvoices.MoveFirst
Do While Not rsInvoices.EOF
nEbu = rsInvoices!EBU\_number
cName = rsInvoices!Surname & rsInvoices!Initial
filepath = "C:\Documents\Invoices\" & cName & ".pdf"
Debug.Print filepath
DoCmd.OpenReport "Monthly\_Invoice", acViewPreview, , "EBU\_Number=" & nEbu, acHidden
DoCmd.OutputTo acOutputReport, "Monthly\_Invoice", acFormatPDF, filepath
DoCmd.Close acReport, "Monthly\_Invoice"
rsInvoices.MoveNext
Loop
MsgBox "All invoices Printed"
End Sub