I have been trying to use a date variable in a stored SQL statement but keep getting "Too few parameters Expected 1" errors. I get this error because the rst is emtpy but everything I have tried doesn't correct the problem. Here is the code I'm using:
Dim db As Database
Dim rst As Recordset
Dim strSQL As String
Dim dtWorkDate As Date
dtWorkDate = Forms!TimeCards!WorkDate
strSQL = "SELECT WorkDate, EmployeeID "
strSQL = strSQL & "FROM TimeCard "
strSQL = strSQL & "WHERE WorkDate >=(dtWorkDate-(Weekday(dtWorkDate))+2) "
strSQL = strSQL & "AND WorkDate <=(dtWorkDate +(8-Weekday(dtWorkDate)));"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
Can anyone suggest corrections? I need to create a recordset containing a week's worth of employee time card info based on a given date (dtWorkDate).
Dim db As Database
Dim rst As Recordset
Dim strSQL As String
Dim dtWorkDate As Date
dtWorkDate = Forms!TimeCards!WorkDate
strSQL = "SELECT WorkDate, EmployeeID "
strSQL = strSQL & "FROM TimeCard "
strSQL = strSQL & "WHERE WorkDate >=(dtWorkDate-(Weekday(dtWorkDate))+2) "
strSQL = strSQL & "AND WorkDate <=(dtWorkDate +(8-Weekday(dtWorkDate)));"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
Can anyone suggest corrections? I need to create a recordset containing a week's worth of employee time card info based on a given date (dtWorkDate).