G
Guest
Hi all,
I'm trying to open a query in VB with some criteria. I tried setting the sql
statement as follows:
"SELECT * FROM qry_Hours WHERE [Emp_ID] = " & Employee & " AND [Date] > #" &
start_date & "# AND [Date] < #" & end_date & "#"
Employee, start_date and end_date already have values based on an open form.
(yes I know I shouldn't be using a field called "date")
When I use this sql statement in db.openrecordset(qry_sql,dbopenforwardonly)
I get the dreaded 3061 'too few parameters, expected 1' error.
After reading a lot of other posts and other stuff on msdn, It seems that I
can't have a WHERE clause in the sql because the parameters need to be
resolved before being passed to Jet. Apparently I need to set the parameters
in querydefs but I haven't found a clear syntax for that. This is the current
code being used, if you could tear it apart and tell me whats wrong that
would be awesome.
Dim db As DAO.Database
Dim rst_qry As DAO.Recordset
Dim qry_sql as string
qry_sql = "**see above**"
Set rst_qry = db.openrecordset(qry_sql,dbopenforwardonly)
Thanks!
RY
I'm trying to open a query in VB with some criteria. I tried setting the sql
statement as follows:
"SELECT * FROM qry_Hours WHERE [Emp_ID] = " & Employee & " AND [Date] > #" &
start_date & "# AND [Date] < #" & end_date & "#"
Employee, start_date and end_date already have values based on an open form.
(yes I know I shouldn't be using a field called "date")
When I use this sql statement in db.openrecordset(qry_sql,dbopenforwardonly)
I get the dreaded 3061 'too few parameters, expected 1' error.
After reading a lot of other posts and other stuff on msdn, It seems that I
can't have a WHERE clause in the sql because the parameters need to be
resolved before being passed to Jet. Apparently I need to set the parameters
in querydefs but I haven't found a clear syntax for that. This is the current
code being used, if you could tear it apart and tell me whats wrong that
would be awesome.
Dim db As DAO.Database
Dim rst_qry As DAO.Recordset
Dim qry_sql as string
qry_sql = "**see above**"
Set rst_qry = db.openrecordset(qry_sql,dbopenforwardonly)
Thanks!
RY