
SQL-statement using Date-function?
Quote:
> Dear friends
> In a table a field is containing dates. From the table I
want to retrieve
> all records where fldDate is within the previous 7 days. I
tried this:
> mySQL = "SELECT * FROM Table WHERE fldDate >= #" & Date -
7 & "#"
> But this cause error like syntaxerror in date in query....
> I have also tried this:
> mySQL = "SELECT * FROM Table WHERE fldDate >= " & Date - 7
> Anybody helps me with this task and tell me what is wrong?
> Regards Able
I presume the 'Date' you mention above is not the name of
the variable as it is a reserved word. You need to do
something like:
mySQL = "SELECT * FROM Table WHERE fldDate >= #" & Date - 7
& "#"
dim dtLastWeek as date
dim dtNow as date
dtNow = Now
dtLastWeek = DateAdd("d", -7, dtNow)
mySQL = "SELECT * FROM Table WHERE fldDate >= #"
Month(dtLastweek) & "/" & Day(dtLastWeek) & "/" &
Year(dtLastweek) & "#"
--
John Blessing
http://www.LbeHelpdesk.com - home of the free helpdesk