Solved

Access 2016 SQL INSERT statement via Excel VBA ADO mystery

Posted on 2016-09-23
7
44 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 49

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 35

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 49

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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