Hello,
In the following code, I keep getting an error that says "too few parameters. Expected 3". I cannot for the life of me understand why.
The process:
On frmAccountingDatabaseInput, the user selects a date and invoice type. The Report, "RptInvoice" is supposed to create, and save to the desktop, a copy for each record in tblAccoutingDatabase that matches the criteria.
As far as I can tell, parameters have been defined. Can someone PLEASE tell me what is wrong with this code? I feel like I'm taking crazy pills!
VBA:
Code:
Sub Save_Invoices_Meet_Criteria()
Dim FileName As String
Dim FilePath As String
Dim myStmt As String
Dim Db As DAO.Database
Dim myrs As DAO.Recordset
Dim qdf As DAO.QueryDef
Set Db = CurrentDb()
Set qdf = Db.QueryDefs("qryCreateInvoicesApproved")
qdf!approve_param = 1
qdf!date_param = [Forms]![frmAccountingDatabaseInput]![Combo272]
qdf!type_param = [Forms]![frmAccountingDatabaseInput]![Combo274]
DoCmd.SetParameter "approve_param", """" & Yes & """"
DoCmd.SetParameter "date_param", """" & [Forms]![frmAccountingDatabaseInput]![Combo272] & """"
DoCmd.SetParameter "type_param", """" & [Forms]![frmAccountingDatabaseInput]![Combo274] & """"
Set myrs = CurrentDb.OpenRecordset("SELECT * from qryCreateInvoicesApproved", 2)
Do Until myrs.EOF
FileName = Me.reference
foldername = Format(Now(), "YYYY-MM-DD")
FilePath = "C:\Users\company\Desktop\Invoicing Database\Save_Test\" & foldername & "\" & FileName & ".pdf"
DoCmd.OpenReport "RPTInvoice", acViewPreview
DoCmd.OutputTo acOutputReport, "RPTInvoice", acFormatPDF, FilePath
DoCmd.Close
myrs.MoveNext
Loop
myrs.Close
Set myrs = Nothing
End Sub
SQL:
Code:
PARAMETERS [approve_param] Bit, [date_param] DateTime, [type_param] Text ( 255 );
SELECT DISTINCT [reference]
FROM tblAccountingDatabase
WHERE (((tblAccountingDatabase.Invoice_approved)=[approve_param])
And ((tblAccountingDatabase.invoice_date)=[date_param])
And ((tblAccountingDatabase.Invoice_Type)=[type_param]));
To anyone who can answer this - You are my hero.