CARA said:
I'M TRYING TO ADD THE FOLLOWING CODE TO AN EVENT ON A
FORM, BUT I'M GETTING A COMPLILE ERROR AND IT'S
HIGHLIGHTING THE *. DO YOU SEE WHAT'S WRONG?
Delete * FROM myTABLE WHERE myFIELD <DateAdd("yyyy","-
3",Date())
TIA,
CARA
(Please don't post all in caps, it's hard to read.)
You don't show the full event procedure, but if that is a complete
statement from it, then it won't work as written, because this is an SQL
statement and you need to package it up as a string and tell Access or
the database engine to execute it. Also, the second argument to
DateAdd() must be a number, not a string. Try this:
Dim strSQL As String
strSQL = _
"DELETE * FROM myTABLE WHERE " & _
"myFIELD < DateAdd(""yyyy"",-3,Date())"
CurrentDb.Execute strSQL, dbFailOnError
An alternative would be to evaluate the DateAdd() function outside the
string and append the calculated date value as a literal:
strSQL = _
"DELETE * FROM myTABLE WHERE " & _
"myFIELD < " &
Format(DateAdd("yyyy",-3,Date()), "\#mm/dd/yyyy\#")
But either approach should work.