Solved

Access 2016 SQL INSERT statement via Excel VBA ADO mystery

Posted on 2016-09-23
7
53 Views
Last Modified: 2016-09-24
When I send this to Access 2016 via ADO/VBA I get an error 'syntax error in INSERT statement'.

But when I copy/paste the same into the Query window in Access it runs OK. No error!

Am I missing something?

Thanks

INSERT INTO tblManualData (ApplicationID, Status, StartDate, Hospital, Induction, InductionDate, DocsOS, CertNo, DBSReturnDate, GeneralNotes, AW, Current, Withdrawn, OnHold) VALUES ('6913078','On Hold','23/09/2016','UCH','Yes','01/01/2016','Birth Certificate',' 11111','20/06/2016','Some notes go here.','23/09/2016','23/09/2016','23/09/2016','23/09/2016')

Open in new window


Note: the Date fields are Date/Time. All others are Short Text. The GeneralNotes is Long Text.
0
Comment
Question by:hindersaliva
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 total points
ID: 41812887
You must use correct string expressions for the date values, like:

VALUES ('6913078','On Hold',#2016/09/23#,'UCH','Yes',#2016/01/01#,'Birth Certificate',  ..etc.

/gustav
0
 

Author Comment

by:hindersaliva
ID: 41812952
Gustav,
It's happy with this though ...

INSERT INTO tblManualData (ApplicationID, Status, StartDate) VALUES ('6913078','On Hold','23/09/2016')

Open in new window


Also it's happy with the UK date format.
0
 
LVL 36

Assisted Solution

by:PatHartman
PatHartman earned 125 total points
ID: 41812985
As long as the date is unambiguous,  Access will "correct" the format.  But 01/05/16 will be JANUARY 5th NOT MAY 1st.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 total points
ID: 41813141
First:
>  I get an error 'syntax error in INSERT statement'.
Then:
> It's happy with this though ...

Both can't be right. The expressions must be as stated to play safe.

/gustav
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 250 total points
ID: 41813463
Is the column [Current] being detected as a reserved word?
0
 

Author Comment

by:hindersaliva
ID: 41813625
Got it!
Yes fanpages. I made it [Current] and it worked. Looks like Current is a reserved word.

Also, I changed the Date data to have # around it. Thanks for the advice.

Thanks all!
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 41813752
You're very welcome :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question