Jack Marley
asked on
MS Access - Too Few Parameters
Hi,
New to MS Access so apologies in advance for glaring errors. I'm trying to leverage an Access template to build a database which can create and print invoices (or save as PDF).
Have a form called "SelectedOrdersToPrint" as he main menu. However when I select the invoices to save, I get "Runtime Error - Too few parameters - Expected 1" which it errors at line "Set rs = CurrentDb.OpenRecordset(st rSQL, dbOpenSnapshot)"
Here's the code in question:
I've attached the Access Database I'm working on. If anyone out there can offer any guidance it'd be much appreciated.
Many thanks.
New to MS Access so apologies in advance for glaring errors. I'm trying to leverage an Access template to build a database which can create and print invoices (or save as PDF).
Have a form called "SelectedOrdersToPrint" as he main menu. However when I select the invoices to save, I get "Runtime Error - Too few parameters - Expected 1" which it errors at line "Set rs = CurrentDb.OpenRecordset(st
Here's the code in question:
Private Sub cmdSaveAsPDF_Click()
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strPathName As String
Dim blRet As Boolean
Dim rs As Recordset
Dim stDocName As String
Dim strSavedSQL As String
If Me.Dirty Then Me.Dirty = False
stDocName = "InvTotal"
strSQL = "SELECT Contracts.OrderID FROM Contracts WHERE (((Contracts.SelectedPrint)=True));"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount < 1 Then
MsgBox "Nothing found to process", vbCritical, "Error"
Exit Sub
End If
CreateFolder CurrentProject.Path & "\Contracts"
' store the current SQL
Set qdf = CurrentDb.QueryDefs("Invoices")
strSavedSQL = qdf.SQL
qdf.Close
Set qdf = Nothing
Do
Set qdf = CurrentDb.QueryDefs("Invoices")
strSQL = Left(strSavedSQL, InStr(strSavedSQL, ";") - 1) & " and (Contracts.OrderID = " & rs!OrderID & ");"
qdf.SQL = strSQL
qdf.Close
Set qdf = Nothing
' put in the same folder as the database
strPathName = CurrentProject.Path & "\Contracts\" & rs!OrderID & ".pdf"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strPathName
rs.MoveNext
Loop Until rs.EOF
rs.Close
Set rs = Nothing
' restore the SQL
Set qdf = CurrentDb.QueryDefs("Invoices")
qdf.SQL = strSavedSQL
qdf.Close
Set qdf = Nothing
End Sub
I've attached the Access Database I'm working on. If anyone out there can offer any guidance it'd be much appreciated.
Many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window