SQL string with date doesn't work

A

Andreas

Hello,

I have a sql-string in my vba code but I think I made a mistake in the
syntax. I tried several things, but get always an error.

Further: the database is used in several countries, do I have to
convert the date (here in Germany it is stored like below)?

sql = "UPDATE tab_Cards_2008 SET num_complete = 1 " & _
"WHERE dat_DateColl = 01.01.1911 OR num_1=99"
DoCmd.RunSQL (sql)

Thank you very much for your help!

Andreas
 
M

Marshall Barton

Andreas said:
I have a sql-string in my vba code but I think I made a mistake in the
syntax. I tried several things, but get always an error.

Further: the database is used in several countries, do I have to
convert the date (here in Germany it is stored like below)?

sql = "UPDATE tab_Cards_2008 SET num_complete = 1 " & _
"WHERE dat_DateColl = 01.01.1911 OR num_1=99"
DoCmd.RunSQL (sql)


Date literals must ben enclosed in # signs and be in either
USA or an unambiguous style.

A way to achieve that is to use this kind of syntax:

"WHERE dat_DateColl = #1911-01-01# OR num_1=99"

If you have a date variable instead of a literal, then use:

"WHERE dat_DateColl = " & Format(dtvar, "\#yyyy-m-d\#") _
& " OR num_1=99"
 

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