0

I'm trying to fix my first INSERT INTO statement for school. Here is the string for the CurrentDb.Execute strSQL

strSQL = "INSERT INTO [Procedure] (UserName, Date, StartTime, EndTime, Semester, FacilityID, Doctor, CaseID, ServiceID, RoleName, Trainer, Comment, Updated_By, Updated_Datetime) VALUES ('username', '12/04/2018', '01:30 PM', '02:00 PM', 'Fall', '4', 'Dr. Who', 'Cataract Extraction with Stent For Glaucoma', '4', 'OS', 'Trainer', 'Comment', 'username', '4/23/2018 7:51:00 PM');"

Procedure Field Names:

UserName, Date, StartTime, EndTime, Semester, FacilityID, Doctor, CaseID, ServiceID, RoleName, Trainer, Comment, Updated_By, Updated_Datetime

Any help is really appreciated. Thank you!! -Tyler M

3 Answers 3

2

It's because you have a field in your table that is named the same as reserved word (built in function)

Date

Rename that field in your table, to something better like

DateOfProcedure

and your query will work (after editing your query string also of course)

In Access Debug window (Ctrl + G) you can run

? AccessError(3134)

and it will return

Syntax error in INSERT INTO statement.

While you are there in the debug window type

? date

There is the reserved word you are trying to use for a field name in the table, causing the SQL query to fail.

Also two other tips (optional)

If any of those ID fields are numbers, you don't have to enclose the Value in single quotes (can have no quotes, so long as the whole query string is enclosed in double quotes)

And for date/time fields, you can use # symbol instead of single quotes to enclose a date/time value

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for all the information! It works great now! :D
0

Try putting square brackets around your field names

I know for sure that [Date] is a reserved word in MS-Access - so that one should be wrapped as in

strSQL = "INSERT INTO [Procedure] (UserName, [Date],....

Comments

0

Also, date/time fields must be passed proper values, and no quotes around numeric values:

strSQL = "INSERT INTO [Procedure] (UserName, [Date], StartTime, EndTime, Semester, FacilityID, Doctor, CaseID, ServiceID, RoleName, Trainer, Comment, Updated_By, Updated_Datetime) VALUES ('username', #12/04/2018#, #01:30 PM#, #02:00 PM#, 'Fall', 4, 'Dr. Who', 'Cataract Extraction with Stent For Glaucoma', 4, 'OS', 'Trainer', 'Comment', 'username', Now());"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.