Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenArgs is Null issue

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

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

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?

like image 989
lamcro Avatar asked Nov 03 '08 12:11

lamcro


2 Answers

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.

Example:

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

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 
like image 100
Philippe Grondier Avatar answered Sep 28 '22 02:09

Philippe Grondier


This often happens during developpment whem the form is already oppened (in edit mode for example) and you invoke the docmd.OpenForm function. In this case, the form is placed in normal (view) mode and the OnOpen and OnLoad events are raised, but the OpenArgs property is set to null no mater what you passed to docmd.OpenForm.

The solution is obviously to close the form before you invoke it with docmd.OpenForm. However there is a workaround I like to use. In the OnOpen event I check if me.OpenArgs is null and if it is I replace it with some debug values.

if not isnull(me.OpenArgs) then
   myvalue = me.OpenArgs
else
   msgbox "Debug mode"
   myValue = "foo"
endif
like image 26
Mathieu Pagé Avatar answered Sep 28 '22 00:09

Mathieu Pagé