OpenArgs是空的错误错误、OpenArgs

2023-09-08 11:07:57 作者:在回忆里流浪

我现在用的是 OpenArgs 参数发送的值时,使用 DoCmd.OpenForm

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

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

我然后用 Me.OpenArgs 打开表单内抢在的值的。它有时会发送一个空值,而不是原始字符串。什么是错的?

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的的.properties集(myFormName)的对象。当你需要的值传递给形式(如从另一个控件或另一种形式的继承,例如过滤器),只需添加相应的属性表单,和你的值添加到这个属性。

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上升),这将作为错误管理code一个新的属性。

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
 
精彩推荐
图片推荐