Datetime Parameter problem

  • Thread starter Thread starter Phill
  • Start date Start date
P

Phill

I have a query that needs to filter by date/time (work
shifts (Between 3/2/04 7:00:00 PM AND 3/3/04 7:00:00
AM). I tried setting up the query 2 ways 1) with a
string parameter that contained the Between clause, and
2) 2 datetime parameters (FromDate and ToDate) and the
where clause of the query was Between [FromDate] and
[EndDate]. Neither way works. I get and error saying
either wrong data type or wrong number of parameters #
expected. What is the correct way to do this? Oh, my
code for executing the query is:
Dim qdf as QueryDef

set qdf=currentdb.querydefs("query1")
with qdf
.parameters("FromDate")="3/2/04 7:00:00 PM"
.parameters("EndDate")="3/3/04 7:00:00 AM"
.execute
end with
 
Phill,

Dim db As Database
Dim sSQL As String
Dim dteFromDate As Date
Dim dteEndDate As Date

Set db = CurrentDb
dteFromDate = DateSerial(2004, 3, 2) + TimeSerial(19, 0, 0)
dteEndDate = DateSerial(2004, 3, 3) + TimeSerial(7, 0, 0)

sSQL = "SELECT * FROM Query1 WHERE SomeDate BETWEEN #" & _
dteFromDate & "# AND #" & dteEndDate & "#", dbFailOnError

db.Execute sSQL, dbFailOnError
Set db = Nothing

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top