I'm new to defining a query in VBA (this is the first time) and I'm getting an error message: Too few parameters. Expected 5. Here is the code that I'm using:
In researching the error message I found that this is a common error message when a field is misspelled. Since I copied almost all of the code from a working query, I'm thinking that the problem is in line 17 where I'm trying to pass the variable lngInvoiceID to the query. I'm thinking that since the query doesn't work by itself, it is causing the error.
Is it possible to set the value of tblACHFiles.Inv oiceID to the variable lngInvoiceID?
Code:
Dim dbBilling As DAO.Database Dim rstInvoices As DAO.Recordset Dim lngInvoiceID As Long Set dbBilling = CurrentDb Set rstInvoices = dbBilling.OpenRecordset("tblInvoices") rstInvoices.AddNew rstInvoices("CustomerID").Value = Forms!frmCustomer!CustomerID rstInvoices("BeginDate").Value = Forms!frmCustomer!txtStartDate lngInvoiceID = rstInvoices!InvoiceID rstInvoices.Update DoCmd.SetWarnings False CurrentDb.Execute "UPDATE tblFileTypes " & _ "INNER JOIN tblACHFiles ON tblFileTypes.FileTypeID = tblACHFiles.CompanyFileID " & _ "SET tblACHFiles.InvoiceID = lngInvoiceID " & _ "WHERE (((tblACHFiles.ACHCompanyID)=[Forms]![frmCustomer]![CustomerID]) " & _ "AND ((tblACHFiles.EffectiveDate)>=[Forms]![frmCustomer]![txtStartDate] " & _ "AND (tblACHFiles.EffectiveDate)<=[Forms]![frmCustomer]![txtEndDate]) " & _ "AND ((tblFileTypes.BillingNumber)=[Forms]![frmCustomer]![cmbBillingNumber]))" DoCmd.SetWarnings True
Is it possible to set the value of tblACHFiles.Inv oiceID to the variable lngInvoiceID?
Comment