Question : MS Access 2003 - Run-time error 3061 with SQL queries and report

Error:  Too few parameters. Expected 2. (Error 3061)

I created a rather complex SQL query found below that when opened, works just fine, and I can sort it however I want.  The SQL query looks at the date range found on form frmReportDateRange for its filter, and I suspect that to be the cause of my error, however, I don't know what needs to be done differently in order for the report to pull the data correctly.  Where I'm receiving the error is in the VBA of a report that I created.  In the Report_Open event, I have another query pull a count from the massive main query that I created, and the recordset for this second query is opened and [TotalGoals] is the represented value of the count from the second query (illustrated below).  There are no errors when opening the second query by itself either, just when the report attempts to view the count from this second query.  

Am I missing some sort of formatting here?  What seems to be the issue?   Any help would be greatly appreciated, and thanks ahead of time.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
MAIN SQL:
-------------------
SELECT Admit.AdmitID, Admit.ClientID, Admit.AdmitDate, Admit.DischargeDate, DateDiff("d",[AdmitDate],[Dischargedate]) AS StayRange, IIf(DateDiff("d",[Admit].[AdmitDate],[Admit].[Dischargedate])<=7,True,False) AS Under7Days, qryGoalDays.OpenDate, qryGoalDays.CloseDate, qryGoalDays.GoalDays, DateAdd("d",[qryGoalDays].[GoalDays],[qryGoalDays].[OpenDate]) AS FinalDate, IIf(IsNull([CloseDate]-[FinalDate]),"0",([CloseDate]-[FinalDate])) AS StayedComp
FROM Admit INNER JOIN qryGoalDays ON Admit.AdmitID = qryGoalDays.AdmitID
WHERE (((Admit.DischargeDate)>=#12/31/2008# Or (Admit.DischargeDate) Is Null) AND ((IIf(DateDiff("d",[Admit].[AdmitDate],[Admit].[Dischargedate])<=7,True,False)) Not Like -1) AND ((qryGoalDays.GoalDays) Not Like 0) AND ((DateAdd("d",[qryGoalDays].[GoalDays],[qryGoalDays].[OpenDate]))>=[Forms]![frmReportDateRange]![txtBeginDate] And (DateAdd("d",[qryGoalDays].[GoalDays],[qryGoalDays].[OpenDate]))<=[Forms]![frmReportDateRange]![txtEndDate]));
 
PROBLEM SQL:
-----------------------
SELECT Count([FinalDate]) AS TotalGoals
FROM qry7DayCutOff;
 
 
WHERE ERROR 3061 SHOWS UP IN VBA:
-----------------------
Private Sub Report_Open(Cancel As Integer)
    Dim strCloseDate As String
    Dim strSQL As String
    Dim strFilterDays As String
    
    Dim db As Database
    Dim rs As Recordset
    
    mstrBeginDate = Forms!frmReportDateRange!txtBeginDate
    mstrEndDate = Forms!frmReportDateRange!txtEndDate
 
'Setup
    Set db = CurrentDb
   
'Count of clients whose goal plans closed this period
    strSQL = "SELECT [TotalGoals] FROM qry7Total"
        
    Set rs = db.OpenRecordset(strSQL)  <--- right here is the "Too few parameters.  Expected 2."

Answer : MS Access 2003 - Run-time error 3061 with SQL queries and report

In the above example, I pick up the dates from custom db properties (I save the values from the form to these properties), but you can pick them up directly from the form.
Random Solutions  
 
programming4us programming4us