1

请帮助我这个引发错误的查询引发错误:在语句末尾缺少分号(;)

SQL = "INSERT INTO rsANALYSIS values ( " & _
  "Chemname, Startvalue, StopValue, Received, [Usage], Quotum ) " & _
  "SELECT '" & rsMainList("handelsnaam") & "', " & StartStock & _
  ", " & StopStock & ", " & Stockreceived & ", " & Stockusage & _
  ", " & rsMainList("quotumlt") & ";"
4

3 回答 3

1

Access INSERT 语句有 2 种语法样式:

  1. INSERT INTO TableName (field list) VALUES (value list)
  2. 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") & ";"
于 2012-09-24T08:50:29.950 回答
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
于 2012-09-24T08:36:01.487 回答
1

我不确定这一点,可能在 INSERT 查询的末尾

SQL = "INSERT INTO rsANALYSIS values ( Chemname, Startvalue, 
StopValue, Received, [Usage], Quotum ); 

SELECT '" & rsMainList("handelsnaam") & "', " & StartStock & ", " & StopStock & ", " & Stockreceived & ", " & Stockusage & ", " & rsMainList("quotumlt") & ";"

还要确保未引用的变量不为空

于 2012-09-24T08:36:14.957 回答