0

我正在尝试在按钮单击事件上进行插入,并且我不断收到查询表达式中缺少运算符的运行时错误,我的查询如下所示。有任何想法吗?

Private Sub CmdAdd_Click()
Dim strSql As String

strSql = "INSERT INTO Current_Costs(PO_Number,Lineitemid,Capital_detail,CapitalID,GL_Number,Cost_Type,Cost_Center,Cost_cat,Item_Cost,PO_Date)" & _
" VALUES (" & Me.txtPONum & "','" & _
    Me.cmbCapDetail & "','" & _
    Me.cmbCapDetail.Column(1) & "','" & _
    Me.txtCapID & "','" & _
    Me.txtGLNum & "','" & _
    Me.cmbCostType & "','" & _
    Me.txtCostCen & "','" & _
    Me.cmbCostCat & "','" & _
    Me.txtCost & "','" & _
    Me.TxtPODate & "')"

   DoCmd.RunSQL strSql

我有一个类似的查询有同样的问题,我看不到问题

 CurrentDb.Execute ("UPDATE Current_Costs " & _
    "SET PO_Number='" & Me.txtPONum & "'" & _
    ",Lineitemid='" & Me.cmbCapDetail & "'" & _
    ",Capital_detail='" & Me.cmbCapDetail.Column(1) & "'" & _
    ",CapitalID='" & Me.txtCapID & "'" & _
    ",GL_Number='" & Me.txtGLNum & "'" & _
    ",Cost_Type='" & Me.cmbCostType & "'" & _
    ",Cost_Center='" & Me.txtCostCen & "'" & _
    ",Cost_cat='" & Me.cmbCostCat & "'" & _
    ",Item_Cost='" & Me.txtCost & "'" & _
    ",PO_Date='" & Me.TxtPODate & "'" & _
    "WHERE LineItemPOID=" & Me.txtID.Tag)

编辑解决

4

1 回答 1

1

" VALUES (" & Me.txtPONum & "','" & _ 

是简短的报价,应该是

" VALUES ('" & Me.txtPONum & "','" & _

把你的sql写成一个字符串,这样更容易看出问题:

strSql = "UPDATE Current_Costs " & _
"SET PO_Number='" & txtPONum & "'" & _
",Lineitemid='" & cmbCapDetail & "'" & _
",Capital_detail='" & cmbCapDetail.Column(1) & "'" & _
",CapitalID='" & txtCapID & "'" & _
",GL_Number='" & txtGLNum & "'" & _
",Cost_Type='" & cmbCostType & "'" & _
",Cost_Center='" & txtCostCen & "'" & _
",Cost_cat='" & cmbCostCat & "'" & _
",Item_Cost='" & txtCost & "'" & _
",PO_Date='" & TxtPODate & "'" & _
" WHERE LineItemPOID=" & txtID


Dim db As database
Set db = CurrentDB
db.Execute strsql dbFailOnError

您在 WHERE 之前缺少一个空格,并且括号不匹配。

考虑使用参数:语句结束错误

于 2013-02-18T16:47:55.400 回答