本文介绍了OpenArgs 是 Null 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 DoCmd.OpenForm 时使用 OpenArgs 参数发送一个值:

I am using the OpenArgs parameter to send a value when using DoCmd.OpenForm:

DoCmd.OpenForm "frmSetOther", acNormal, , , acFormAdd, acDialog, "value"

然后我在打开的表单中使用 Me.OpenArgs 来获取.它有时会发送一个 Null 值而不是原始字符串.怎么了?

I then use Me.OpenArgs inside the opened form to grab the value. It sometimes sends a Null value instead of the original string. What is wrong?

推荐答案

这个openArgs"参数的一个非常有趣的替代方法是使用 currentProject.allforms("myFormName") 对象的 .properties 集合.当您需要向表单传递值(例如从另一个控件或另一个表单继承的过滤器)时,只需为您的表单添加相应的属性,并将您的值添加到该属性中.

A very interesting alternative to this "openArgs" argument is to use the .properties collection of the currentProject.allforms("myFormName") object. When you need to pass a value to a form (such as a filter inherited from another control or another form, for example), just add the corresponding property for your form, and add your value to this property.

示例:

addPropertyToForm "formFilter","Tbl_myTable.myField LIKE 'A*'",myFormName

被调用的函数将尝试更新对象的formFilter"属性的值.如果该属性不存在(引发 err 2455),则会在错误管理代码中作为新属性添加.

The called function will try to update the value of the "formFilter" property of the object. If the property does not exist (err 2455 is raised), it will be added as a new property in the error management code.

Function addPropertyToForm(_ 
    x_propertyName as string, _
    x_value As Variant, _
    x_formName As String) 
As Boolean

On Error GoTo errManager
CurrentProject.AllForms(x_formName).Properties(x_propertyName).Value = x_value
addPropertyToForm = True
On Error GoTo 0

Exit Function

errManager:
If Err.Number = 2455 Then
    CurrentProject.AllForms(x_formName).Properties.Add x_propertyName, Nz(x_value)
    Resume Next
Else
    msgbox err.number & ". The property " & x_propertyName & "was not created"
End If

End Function 

这篇关于OpenArgs 是 Null 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:42