SQL Update and NOW

J

Jay

I have code in a module as follows:

strSql = "Update tbl_admin Set tbl_admin.email_LastDateSent = " & Now
DoCmd.RunSQL strSql

The field email_LastDateSent is a Date field. I get an error message
"Syntax error (missing operator)" What syntax am I missing.

Thanks
 
C

ChrisJ

try...

strSql = "Update tbl_admin Set tbl_admin.email_LastDateSent = #" & Now & "#"

the hashes are needed for dates just like quotes are needed for strings
 
J

Jay

Thanks Chris,

Will this then post the time portion as well as I would like the date
and time in the same field.

-----Original Message-----
From: ChrisJ [mailto:[email protected]]
Posted At: Thursday, March 18, 2010 9:11 PM
Posted To: microsoft.public.access.queries
Conversation: SQL Update and NOW
Subject: RE: SQL Update and NOW



try...

strSql = "Update tbl_admin Set tbl_admin.email_LastDateSent = #" & Now
& "#"

the hashes are needed for dates just like quotes are needed for strings
 
B

Bob Barrows

Jay said:
I have code in a module as follows:

strSql = "Update tbl_admin Set tbl_admin.email_LastDateSent = " & Now
DoCmd.RunSQL strSql

The field email_LastDateSent is a Date field. I get an error message
"Syntax error (missing operator)" What syntax am I missing.
Simply change it to:
strSql = "Update tbl_admin Set tbl_admin.email_LastDateSent = Now()"

There is no need for the concatenation. Jet is perfectly capable of
running the Now function.

And yes, Now returns time as well as date. To get date-only, use the
Date function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top