为什么 DoCmd.SetParameter 'expression' 参数需要控件的名称,而不是值?
Why does DoCmd.SetParameter 'expression' parameter expects the name of a control, not a value?
DoCmd.SetParameter
的文档说:
expression. SetParameter( _Name_, _Expression_ )
expression A variable that represents a DoCmd object.
Parameters
Name Required/Optional Data type Description
Name Required Variant The name of the parameter. The name must
match the name of the parameter
expected by the BrowseTo, OpenForm,
OpenQuery, OpenReport, or RunDataMacro method.
Expression Required Variant An expression that evaluates to a value to
assign to the parameter.
但是当我尝试这个时:
DoCmd.SetParameter "sAction", "UPDATE"
我收到错误消息
Run-time error '2482':
Vendor Compliance System cannot find the name 'UPDATE' you entered in the expression.
所以我创建了一个名为 "frmTEMP" 的表单,其中包含一个文本框 "sAction",然后尝试了这个,效果很好:
DoCmd.SetParameter "sAction", "forms!frmTEMP!sAction"
所以我的问题是,为什么 DoCmd.SetParameter 'expression' 参数需要控件的名称,而不是值?由于手边没有打开的表单,我该如何为 SetParameter 提供一个值?
June7 提供了解决我问题的答案。谢谢!
所以,这是我的代码:
Public Sub sendEvent_ValueChange(RecordID As Long, TableID As String,
ValueID As String, newVal As Variant, oldVal As Variant)
DoCmd.SetParameter "sTable", TableID
DoCmd.SetParameter "sField", ValueID
DoCmd.SetParameter "sAction", "UPDATE"
DoCmd.SetParameter "recordID", RecordID
DoCmd.SetParameter "value_Old", oldVal
DoCmd.SetParameter "value_New", newVal
DoCmd.RunDataMacro "ChangeLog.AddLog"
End Sub
这个子的想法是,当用户修改一个未绑定的控件时,afterUpdate 事件将调用它发送 table/source 名称、字段名称、旧值和新值到 "ChangeLog" table。 "AddLog" 是这个 table 上的命名数据宏,它检查数据类型(布尔、长、字符串等)并将数据放入正确类型的字段中。
问题是它正在查找 "SetParameter" 命令的第二个参数作为打开表单上控件的名称,而不仅仅是一个值。要将它解释为一个值,它必须用引号括起来,例如
DoCmd.SetParameter "sTable", "'" & TableID & "'"
DoCmd.SetParameter "sAction", "'UPDATE'"
等等
DoCmd.SetParameter
的文档说:
expression. SetParameter( _Name_, _Expression_ )
expression A variable that represents a DoCmd object.
Parameters
Name Required/Optional Data type Description
Name Required Variant The name of the parameter. The name must
match the name of the parameter
expected by the BrowseTo, OpenForm,
OpenQuery, OpenReport, or RunDataMacro method.
Expression Required Variant An expression that evaluates to a value to
assign to the parameter.
但是当我尝试这个时:
DoCmd.SetParameter "sAction", "UPDATE"
我收到错误消息
Run-time error '2482':
Vendor Compliance System cannot find the name 'UPDATE' you entered in the expression.
所以我创建了一个名为 "frmTEMP" 的表单,其中包含一个文本框 "sAction",然后尝试了这个,效果很好:
DoCmd.SetParameter "sAction", "forms!frmTEMP!sAction"
所以我的问题是,为什么 DoCmd.SetParameter 'expression' 参数需要控件的名称,而不是值?由于手边没有打开的表单,我该如何为 SetParameter 提供一个值?
June7 提供了解决我问题的答案。谢谢!
所以,这是我的代码:
Public Sub sendEvent_ValueChange(RecordID As Long, TableID As String,
ValueID As String, newVal As Variant, oldVal As Variant)
DoCmd.SetParameter "sTable", TableID
DoCmd.SetParameter "sField", ValueID
DoCmd.SetParameter "sAction", "UPDATE"
DoCmd.SetParameter "recordID", RecordID
DoCmd.SetParameter "value_Old", oldVal
DoCmd.SetParameter "value_New", newVal
DoCmd.RunDataMacro "ChangeLog.AddLog"
End Sub
这个子的想法是,当用户修改一个未绑定的控件时,afterUpdate 事件将调用它发送 table/source 名称、字段名称、旧值和新值到 "ChangeLog" table。 "AddLog" 是这个 table 上的命名数据宏,它检查数据类型(布尔、长、字符串等)并将数据放入正确类型的字段中。
问题是它正在查找 "SetParameter" 命令的第二个参数作为打开表单上控件的名称,而不仅仅是一个值。要将它解释为一个值,它必须用引号括起来,例如
DoCmd.SetParameter "sTable", "'" & TableID & "'"
DoCmd.SetParameter "sAction", "'UPDATE'"
等等