使用变量

时间:2017-09-12 18:53:09

标签: access-vba ms-access-2013

我正在尝试通过docmd.RunSql更新表,但无法让它更新。

idlook = DLookup("[ID]", "119_review", "[todays_date] = #" & Format("" & Me.Combo87 & " " & Me.Combo89 & " 20" & Me.Combo91 & "", Medium) & "#")

MySQL = "UPDATE 119_review SET [Earned_Income]=" & Val(EarnedIncome) & " AND [Earned_income_withcal]=" & Val(EarnedIncomeCal) & " WHERE [ID]= " & idlook & ";"

Debug.Print MySQL
DoCmd.RunSQL MySQL

我在字段上使用和不使用括号都尝试过,立即窗口显示:

UPDATE 119_review SET Earned_Income=62 AND Earned_income_withcal=58.4 WHERE ID= 23;
UPDATE 119_review SET [Earned_Income]=62 AND [Earned_income_withcal]=58.4 WHERE [ID]= 23;

我知道哪里出错了?

1 个答案:

答案 0 :(得分:1)

您发出了一个简单的语法错误。

更新语句中的不同列应由,分隔,而不是AND。 奇怪的是,做错了并不会引发语法错误,但只是没有更新任何内容。

将SQL字符串的行设置更改为以下内容:

MySQL = "UPDATE 119_review SET [Earned_Income]=" & Val(EarnedIncome) & " , [Earned_income_withcal]=" & Val(EarnedIncomeCal) & " WHERE [ID]= " & idlook & ";"