下面的代码创建一个SQL字符串,该字符串在MS Access中产生语法错误(3134)。
sql = "INSERT INTO tblItems (desc, descExtended, itemNumber, currentPrice) " & _ "VALUES (" & _ "'" & rs.Fields("Field6") & "', " & _ "'" & rs.Fields("Field7") & "', " & _ rs.Fields("Field1") & ", " & _ rs.Fields("Field8") & _ ")" db.Execute sql, dbFailOnError
产生语法错误的“ sql”字符串的值为:
“将tblItems(desc,descExtended,itemNumber,currentPrice)插入值(’APPLE GRANNY SMITH SLI IQF’,’GEMS OF FRUIT’,2050791,49)”
表和字段名称正确。“ desc”和“ descExtended”字段的类型为文本。“ itemNumber”和“ currentPrice”是数字。
这是您的字段名称。DESC是SQL的降序描述。DESC是SQL语法中的保留字。您将需要将其放入[]或对其进行更改。(如果不为时过晚,我建议您使用后者,以免将来头疼。)避免将保留字用作表名或字段名。
INSERT INTO tblItems ([desc], descExtended, itemNumber, currentPrice) VALUES ('APPLE GRANNY SMITH SLI IQF', 'GEMS OF FRUIT', 2050791, 49)
或更好
INSERT INTO tblItems (Descript, descExtended, itemNumber, currentPrice) VALUES ('APPLE GRANNY SMITH SLI IQF', 'GEMS OF FRUIT', 2050791, 49)