运行 UPDATE 语句的时间错误 3144
Run time error 3144 from UPDATE statement
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 语法错误。似乎找不到错误。
所以看起来语法有点不对...将代码分成几部分可能会有所帮助...我无法测试这个解决方案,但试试这个(这完全取决于数据类型) :
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 & ""
考虑使用 parameterized query with MS Access' QueryDefs 来准确指定绑定值的数据类型,并避免导致难以维护代码的连接和引号换行。根据需要在 PARAMETERS
子句中调整以下类型(符合 Access SQL)。
SQL (仅保存一次 MS Access 存储查询)
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];
VBA (将值动态绑定到参数占位符)
Dim qdef as QueryDef
Set qdef = CurrentDb.QueryDefs("mySavedQuery")
qdef![txtreceipt_id_PARAM] = txtreceipt_id
qdef![txttdate_PARAM] = txttdate
qdef![txttotal_cost_PARAM] = txttotal_cost
qdef![txttotal_disc_PARAM] = txttotal_disc
qdef.Execute dbFailOnError
Set qdef = Nothing
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 语法错误。似乎找不到错误。
所以看起来语法有点不对...将代码分成几部分可能会有所帮助...我无法测试这个解决方案,但试试这个(这完全取决于数据类型) :
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 & ""
考虑使用 parameterized query with MS Access' QueryDefs 来准确指定绑定值的数据类型,并避免导致难以维护代码的连接和引号换行。根据需要在 PARAMETERS
子句中调整以下类型(符合 Access SQL)。
SQL (仅保存一次 MS Access 存储查询)
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];
VBA (将值动态绑定到参数占位符)
Dim qdef as QueryDef
Set qdef = CurrentDb.QueryDefs("mySavedQuery")
qdef![txtreceipt_id_PARAM] = txtreceipt_id
qdef![txttdate_PARAM] = txttdate
qdef![txttotal_cost_PARAM] = txttotal_cost
qdef![txttotal_disc_PARAM] = txttotal_disc
qdef.Execute dbFailOnError
Set qdef = Nothing