通过 SQL 使用变量更新 table

updating table via SQL with variables

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

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

我已经尝试过在字段中使用和不使用括号,直接 window 显示:

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;

知道我哪里出错了吗?

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

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

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

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