Click here to Skip to main content
15,885,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am updating a record in Micro-Soft Access-2003. (Yes, 2003.....)
When reading the record the dateTime is '2019-07-31T00:00:00.000'.

When doing a query on the table, I can search the dateTime using a jullian date, the fractional part being the time of day and works fine in this new application and an other that has been running for a year, but does not do an update.

The error is: Syntax Error on UPDATE.

Using a tool to connect, using odbc, to the database, I have found that the error occurs on the dateTime field.

update scans1 set
date = '2019-07-31T00:00:00.000'
where id = 21570


(Upgrading access is not an option as many features used are no longer available. Other options have been rejected also.)

What I have tried:

Things I have tried:
bracketing the dateTime #: '#2019-07-31T00:00:00.000#'
using just the date, with and without #'s '07/31/2019' using / and -
Date and time '07/31/2019 12:00 AM' and with -
Putting the year-month-day
Converting the date to jullian and jullian with the offset of 12/31/1899
Various date formats.

Once the code failed, I needed to track-down the error. To do this, I used a tool that allows sql commands through an interface. (This is a sample program included with QT, sqlbrowser.) I am able to connect and perform queries, inserts, updates, etc. I am able to update a non-dateTime column but get syntax errors updating datetime columns.

Updates I have tried include:
update scans1 set date = '2019-07-31T00:00:00.000' where id = 21570
update scans1 set date = '7/31/2019' where id = 21570
update scans1 set date = 2415319.25 where id = 21570
update scans1 set date = 43708.5 where id = 21570

As I was updating this question with the code, I saw the issue.
A column name of date. (Why this is, I do not know. This is a legacy application.)

This can be closed. Thanks.
Posted
Updated 3-Sep-19 2:41am
v2
Comments
Dave Kreskowiak 2-Sep-19 14:05pm    
Without seeing the code that's generating the UPDATE statement, it's impossible to tell you what's going wrong.
Patrice T 2-Sep-19 19:23pm    
Publish the update as a solution and accept it, it will close the question.

1 solution

Couple of things from a fellow legacy application support type

You can still use the column "date", just surround it with square brackets. I.e.
SQL
update scans1 set [date] = '2019-07-31T00:00:00.000' where id = 21570
I was still getting an error until I changed it to
SQL
update scans1 set [date] = CDate('2019-07-31') where id = 21570
 
Share this answer
 
Comments
ZurdoDev 3-Sep-19 16:33pm    
As I recall, Access wants #'s around it's dates.

I think

update scans1 set [date] = '#2019-07-31T00:00:00.000#' where id = 21570

would have also worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900