L
Leonard Priestley
I am trying to restrict a recordset to those records which concern a
particular person, and which lie between two dates. The start and finish
dates are specified in two textboxes - txtStartDate and txtEndDate - and the
PersonID is taken from a textbox, txtPersonID, which is bound to the field
[PersonID] in a table.
So far I have this:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT [PersonID], [DateOfInterest] FROM tblShiftTime " & _
"WHERE [PersonID] = Me.txtPersonID AND [DateOfInterest] >= Me.txtStartDate
" & _
"AND [DateOfInterest] <= Me.txtEndDate"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
When I try to run this, I get the error message "Too few parameters:
Expected 3"
This seems to be referring to the three fields specified in the WHERE
statement. If I comment the
WHERE statement out, I do not get an error message, and if I reduce the
number of fields referred to,
the error message changes the number of expected parameters accordingly.
The problem arises at the
line: Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
At the time I run the code, all three textboxes referred to have sensible
data in them.
Any ideas anyone?
Leonard Priestley
particular person, and which lie between two dates. The start and finish
dates are specified in two textboxes - txtStartDate and txtEndDate - and the
PersonID is taken from a textbox, txtPersonID, which is bound to the field
[PersonID] in a table.
So far I have this:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT [PersonID], [DateOfInterest] FROM tblShiftTime " & _
"WHERE [PersonID] = Me.txtPersonID AND [DateOfInterest] >= Me.txtStartDate
" & _
"AND [DateOfInterest] <= Me.txtEndDate"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
When I try to run this, I get the error message "Too few parameters:
Expected 3"
This seems to be referring to the three fields specified in the WHERE
statement. If I comment the
WHERE statement out, I do not get an error message, and if I reduce the
number of fields referred to,
the error message changes the number of expected parameters accordingly.
The problem arises at the
line: Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
At the time I run the code, all three textboxes referred to have sensible
data in them.
Any ideas anyone?
Leonard Priestley