Solved

Access 2016 SQL INSERT statement via Excel VBA ADO mystery

Posted on 2016-09-23
7
40 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 34

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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 Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

932 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now