CurrentDb.Execute "UPDATE Transaction SET receipt_id=" & txtreceipt_id & ", tdate=" & txttdate & ",total_cost=" & txttotal_cost & ",total_disc=" & txttotal_disc & " WHERE receipt_id=" & txtreceipt_id & " "
我得到运行时3144语法错误。似乎无法找到错误。
答案 0 :(得分:0)
所以看起来语法稍微有点......可能有助于将代码分成几部分......我无法测试此解决方案但是尝试这个(这完全取决于数据类型) :
CurrentDb.Execute "UPDATE Transaction " & _
" SET receipt_id = '" & txtreceipt_id & "'" & _
", tdate = " & txttdate & "" & _
", total_cost = " & txttotal_cost & "" & _
", total_disc = " & txttotal_disc & "" & _
" WHERE receipt_id = '" & txtreceipt_id & "'"
如果txreceipt_id是一个数字,请尝试:
CurrentDb.Execute "UPDATE Transaction " & _
" SET receipt_id = " & txtreceipt_id & "" & _
", tdate = " & txttdate & "" & _
", total_cost = " & txttotal_cost & "" & _
", total_disc = " & txttotal_disc & "" & _
" WHERE receipt_id = " & txtreceipt_id & ""
答案 1 :(得分:0)
考虑使用带有MS Access“parameterized query的QueryDefs来准确指定绑定值的数据类型,并避免连接和引用包装,这会使代码难以维护。根据{{1}}子句中的需要调整以下类型(在Access SQL中符合)。
SQL (仅保存为MS Access存储查询一次)
PARAMETERS
VBA (将值动态绑定到参数占位符)
PARAMETERS [txtreceipt_id_PARAM] LONG, [txttdate_PARAM] DATE,
[txttotal_cost_PARAM] DOUBLE, [txttotal_disc_PARAM] DOUBLE;
UPDATE [Transaction]
SET receipt_id = [txtreceipt_id_PARAM],
tdate = [txttdate_PARAM],
total_cost = [txttotal_cost_PARAM],
total_disc = [txttotal_disc_PARAM]
WHERE receipt_id = [txtreceipt_id_PARAM];