2013-02-18 96 views
0

我想在按鈕上單擊事件做一個插入操作,並且在查詢表達式中我一直收到運行時錯誤的運算符錯誤,我的查詢如下所示。有任何想法嗎?運行時錯誤3075無法弄清楚

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) 

編輯解決

+1

這' 「VALUES(」 &Me.txtPONum& 「 ''」 &_'是短一個報價,它應該是'」 VALUES('」&Me.txtPONum& 「','」&_'。但是我不認爲這會給你引用的錯誤號碼。 – Fionnuala 2013-02-18 16:37:10

+0

謝謝你生病了試試 – user1902540 2013-02-18 16:41:09

+0

謝謝 – user1902540 2013-02-18 16:47:15

回答

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 

你失蹤哪裏,你有一個無與倫比的括號之前的空間。

考慮使用參數:End of statement error

+0

感謝您的答案,我編輯了另一個具有相同問題的查詢,我不能看到錯誤 – user1902540 2013-02-18 19:13:10