May be this has been solved in this forum before but I can't find it. Here it goes.
I have a code I wrote to open a query and use its values to update a table. The query gets its Date range from the StartDate and EndDate controls on the form. The query runs fine if i open it by double-cliking on it while the form is open. But I get errors when I tried opening it from the code eventhough the form is open. I get the following message: TOO FEW PARAMETERS. EXPECTED 2. The query retuns no records. It looks like the code runs the query without picking the values from the date controls on the form. In the query criteria I have the folowing function:
Between [forms]![frmRevReports]![txtBegin] And [forms]![frmRevReports]![txtEnd]
However, when I removed this BETWEEN condition from the criteria in the query, the code runs just fine. That is, when it makes no reference to the date controls on the form.
What do I have to add to get the code to reference the dates on the form and supply them to the criteria of the query, "QRY_REVENUE_MINUTES_OUT_1"
Here is my code. Please help:
I have a code I wrote to open a query and use its values to update a table. The query gets its Date range from the StartDate and EndDate controls on the form. The query runs fine if i open it by double-cliking on it while the form is open. But I get errors when I tried opening it from the code eventhough the form is open. I get the following message: TOO FEW PARAMETERS. EXPECTED 2. The query retuns no records. It looks like the code runs the query without picking the values from the date controls on the form. In the query criteria I have the folowing function:
Between [forms]![frmRevReports]![txtBegin] And [forms]![frmRevReports]![txtEnd]
However, when I removed this BETWEEN condition from the criteria in the query, the code runs just fine. That is, when it makes no reference to the date controls on the form.
What do I have to add to get the code to reference the dates on the form and supply them to the criteria of the query, "QRY_REVENUE_MINUTES_OUT_1"
Here is my code. Please help:
Code:
Dim rstOutGoingMin As Recordset
Dim rstTotalOutMin As Recordset
Dim rstBalanceConsulting As Recordset
Dim mMinutes As Double
Dim mOutgoingCallsCount As Double
Dim currNumber As String
Set db = CurrentDb()
db.QueryTimeout = 0
Set rstOutGoingMin = db.OpenRecordset("QRY_REVENUE_MINUTES_OUT_1", dbOpenForwardOnly)
With rstOutGoingMin
Do While Not .EOF
currNumber = !ANumber
mOutgoingCallsCount = !OutgoingCallsCount
Set rstTotalOutMin = db.OpenRecordset("REVENUE_REPORTS_ACCOUNTS", dbOpenTable)
With rstTotalOutMin
.Index = "PrimaryKey"
.Seek "=", currNumber
If Not .NoMatch Then
.Edit
!Out_Going_Min = mMinutes
!Out_Going_Calls_Count = mOutgoingCallsCount
.Update
End If
End With
.MoveNext
Loop
rstTotalOutMin.Close
End With
rstOutGoingMin.Close