2014-02-19 81 views
3

我需要一些幫助,對不起,我是新的VBA,我試圖運行更新查詢應該從變量獲取值並更新一個已經存在的表格。這是使用VBA完成的。顯示執行時沒有錯誤消息,但表格未用新值更新。代碼如下:我想更新Access VBA中的表中的一些字段

Query = "UPDATE Results " & _ 
     "SET fk_Report='" & Report & "'" & _ 
      ",fk_Name='" & Namevar & "'" & _ 
      ",fk_Age='" & Agevar & "'" & _ 
      ",fk_Sex='" & Sexvar & "'" & _ 
     "WHERE [Count]='" & Countvar & "'" & _ 
      ",[Positives]='" & Posvar & "'" & _ 
      ",[Negatives]='" & Negvar & "'" & _ 
      ",[Unknow]='" & Unkvar & "';" 
    CurrentDb.Execute (Query) 

如果有人可以幫助...

回答

1

你不需要的逗號,而不是在where子句

Query = "UPDATE Results " & _ 
    "SET fk_Report='" & Report & "'" & _ 
     ",fk_Name='" & Namevar & "'" & _ 
     ",fk_Age='" & Agevar & "'" & _ 
     ",fk_Sex='" & Sexvar & "'" & _ 
    "WHERE [Count]='" & Countvar & "' " & _ 
     "AND [Positives]='" & Posvar & "' " & _ 
     "AND [Negatives]='" & Negvar & "' " & _ 
     "AND [Unknow]='" & Unkvar & "';" 
CurrentDb.Execute (Query) 
相關問題