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.
因此,我创建了一个带有文本框“ sAction”的名为“ frmTEMP”的表单,然后尝试了此方法,该方法有效:
DoCmd.SetParameter "sAction", "forms!frmTEMP!sAction"
所以我的问题是,为什么DoCmd.SetParameter'expression'参数需要控件的名称而不是值?由于我没有方便的开放式表单,我该如何为SetParameter提供一个值呢?
答案 0 :(得分:0)
6月7日提供了解决我问题的答案。谢谢!
所以,这是我的代码:
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事件将调用它,以将表/源名称,字段名称,旧值和新值发送到“ ChangeLog”表。 “ AddLog”是此表上的一个命名数据宏,用于检查数据类型(布尔,长整数,字符串等),并将数据放入正确类型的字段中。
问题在于它正在“ SetParameter”命令中查找第二个参数,作为打开窗体上控件的名称,而不仅仅是一个值。要将其解释为值,必须将其用引号引起来,例如
DoCmd.SetParameter "sTable", "'" & TableID & "'"
DoCmd.SetParameter "sAction", "'UPDATE'"
等