请帮我这个抛出错误的查询抛出错误:在语句结尾处缺少分号(;)
SQL = "INSERT INTO rsANALYSIS values ( " & _
"Chemname, Startvalue, StopValue, Received, [Usage], Quotum ) " & _
"SELECT '" & rsMainList("handelsnaam") & "', " & StartStock & _
", " & StopStock & ", " & Stockreceived & ", " & Stockusage & _
", " & rsMainList("quotumlt") & ";"
答案 0 :(得分:1)
您确定所有变量都包含值吗?如果没有,您将收到上述错误。
在大多数情况下,您最好使用参数:
Dim db As Database
Dim qdf As QueryDef
Set db = CurrentDb
sSQL = "INSERT INTO rsANALYSIS values ( " & _
"Chemname, Startvalue, StopValue, Received, [Usage], Quotum ) " & _
"Values ([p1],[p2],[p3],[p4,[p5],[p6])"
''Temporary query
Set qdf = db.CreateQueryDef("", sSQL)
''No need to worry about quotes etc
qdf.Parameters("p1") = rsMainList("handelsnaam")
qdf.Parameters("p2") = StartStock
qdf.Parameters("p3") = StopStock
qdf.Parameters("p4") = Stockreceived
qdf.Parameters("p5") = Stockusage
qdf.Parameters("p6") = rsMainList("quotumlt")
qdf.Execute dbFailOnError
答案 1 :(得分:1)
我不太确定这一点,可能是在INSERT查询结束时
SQL = "INSERT INTO rsANALYSIS values ( Chemname, Startvalue,
StopValue, Received, [Usage], Quotum );
SELECT '" & rsMainList("handelsnaam") & "', " & StartStock & ", " & StopStock & ", " & Stockreceived & ", " & Stockusage & ", " & rsMainList("quotumlt") & ";"
还要确保未加引号的变量不为空
答案 2 :(得分:1)
Access INSERT语句有两种语法样式:
INSERT INTO TableName (field list) VALUES (value list)
INSERT INTO TableName (field list) SELECT statement
您的INSERT
声明似乎正在混合使用这两种风格。以这种方式尝试(没有VALUES
关键字):
SQL = "INSERT INTO rsANALYSIS ( " & _
"Chemname, Startvalue, StopValue, Received, [Usage], Quotum ) " & _
"SELECT '" & rsMainList("handelsnaam") & "', " & StartStock & _
", " & StopStock & ", " & Stockreceived & ", " & Stockusage & _
", " & rsMainList("quotumlt") & ";"