LOUISBUHAGIAR54
Registered User.
- Local time
- Today, 09:54
- Joined
- Mar 14, 2010
- Messages
- 157
I have a code which runs as follows. Basically it opens up a Report containg invoices. The user is prompted to give a year so that only those invoices for that year come up for reporting.
Private Sub Report_Open(Cancel As Integer)
Dim StrSQL As String
StrSQL = " SELECT Particulars.[First Name], Particulars.[Second Name], Particulars.[idcard no], invoicelog.Invoice_no, invoicelog.invoiceamount, invoicelog.paid, invoicelog.[date of issue], Year([date of issue]) AS Expr1" _
& " FROM Particulars INNER JOIN invoicelog ON Particulars.[idcard no] = invoicelog.resident_id" _
& " WHERE (((invoicelog.paid) = Yes) And ((Year([date of issue])) = [Please enter year under study]))" _
& " ORDER BY Particulars.[Second Name];"
Dim sena As Variant
Dim mydb As Database
Dim rst1 As DAO.Recordset
Set mydb = CurrentDb()
Set rst1 = mydb.OpenRecordset(StrSQL)
If rst1.RecordCount = 0 Then Exit Sub
rst1.MoveFirst
sena = rst1![date of issue]
Me.Label20.Caption = "Paid invoices for year " & Year(sena)
Me.recordsource = StrSQL
End Sub
However when the code reaches
Set rst1 = mydb.OpenRecordset(StrSQL)
it stops and displays error 3061 saying
'Too few parameters. Expected 1"
Can someone please explain this error and how it can be corrected ?
Many thanks for your assistance.
LouisB.
Private Sub Report_Open(Cancel As Integer)
Dim StrSQL As String
StrSQL = " SELECT Particulars.[First Name], Particulars.[Second Name], Particulars.[idcard no], invoicelog.Invoice_no, invoicelog.invoiceamount, invoicelog.paid, invoicelog.[date of issue], Year([date of issue]) AS Expr1" _
& " FROM Particulars INNER JOIN invoicelog ON Particulars.[idcard no] = invoicelog.resident_id" _
& " WHERE (((invoicelog.paid) = Yes) And ((Year([date of issue])) = [Please enter year under study]))" _
& " ORDER BY Particulars.[Second Name];"
Dim sena As Variant
Dim mydb As Database
Dim rst1 As DAO.Recordset
Set mydb = CurrentDb()
Set rst1 = mydb.OpenRecordset(StrSQL)
If rst1.RecordCount = 0 Then Exit Sub
rst1.MoveFirst
sena = rst1![date of issue]
Me.Label20.Caption = "Paid invoices for year " & Year(sena)
Me.recordsource = StrSQL
End Sub
However when the code reaches
Set rst1 = mydb.OpenRecordset(StrSQL)
it stops and displays error 3061 saying
'Too few parameters. Expected 1"
Can someone please explain this error and how it can be corrected ?
Many thanks for your assistance.
LouisB.
Last edited: