VBA Access错误3134:INSERT INTO语句语法错误排查求助
Hey there! Let's break down why your INSERT query is throwing that syntax error—Error 3134 in Access almost always ties to reserved words or missing delimiters, and I've spotted the key issue here.
The Main Culprit: Reserved Word Date
Date is a built-in reserved keyword in Access (it refers to the system date function). When you use it as a field name without wrapping it in square brackets [], Access misinterprets your intent, leading to the syntax error.
Fix Steps
- Wrap the
Datefield name in square brackets in your column list. - Confirm your table name
[Procedure]stays wrapped in brackets (you already did this correctly—great call, sinceProcedureis also a reserved SQL word!).
Corrected SQL Statement
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');"
Quick Pro Tip for Future Debugging
If you hit similar syntax errors later, first check if any field/table names match Access's reserved words. Additionally, using parameterized queries instead of hardcoding values will help avoid syntax hiccups with special characters and is a more secure practice overall.
内容的提问来源于stack exchange,提问作者Meneghini

