Design by Sue
Registered User.
- Local time
- Today, 14:26
- Joined
- Jul 16, 2010
- Messages
- 816
I am using the following code to determine if there are no records that match the criteria and if so display a message box. I have tested the code by pasting the SQL in a query SQL window and running it and it works perfectly. Yet I am getting the error message Too Few Parameters - Expected 1. Can someone see my error? The error message trips on the line "Set rs = db.OpenRecordset(strSQL)"
Thanks
Sue
Code:
Dim rs As DAO.Recordset
Dim db As Database
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT MainTBL.QTDate, Year([QTDate]) & Month([QTDate]) AS [Match], SubTBL.Observation FROM MainTBL INNER JOIN SubTBL ON MainTBL.ID = SubTBL.LinkID WHERE (((Year([QTDate]) & Month([QTDate]))=[Forms]![Switchboard]![Match]) AND ((SubTBL.Observation) Like 'Material Defect'))"
Debug.Print strSQL
Set rs = db.OpenRecordset(strSQL)
If rs.Fields.Count = 0 Then
MsgBox "There are no records in this report.", vbExclamation, "No Records"
Set rs = Nothing
Exit Sub
End If
Thanks
Sue