我在此代码中遇到运行时错误3061
:
CurrentDb.Execute "UPDATE [tblCategory]" & _
" SET [Category]=" & Me.txtCat & _
", [Percentage]='" & Me.txtPer & "'" & _
" WHERE [Category]=" & Me.txtCat.Tag
答案 0 :(得分:1)
考虑参数化查询以避免需要字符串连接和引用机箱,因为您在PARAMETERS
子句中明确定义了类型,所有这些都是可读和可维护的例程。下面假设百分比是十进制数(即双精度数)。
SQL (另存为存储的查询)
PARAMETERS [CategParam] Text, [PctParam] Double, [CategTagParam] Text;
UPDATE [tblCategory]
SET [Category] = [CategParam], [Percentage] = [PctParam]
WHERE [Category]= [CategTagParam]
<强> VBA 强>
Dim qdef As QueryDef
Set qdef = CurrentDb.QueryDefs("mySavedQuery")
qdef![CategParam] = Me.txtCat
qdef![PctParam] = Me.txtPer
qdef![CategTagParam] = Me.txtCat.Tag
qdef.Execute dbFailOnError
Set qdef = Nothing