Robust solution to allow easy passing of arguments to forms
Hi there,
I want to develope a robust way of being able to pass arguments to a form when opening it. This way, I can treat the form basically like a function - and it severs the opening forms usual dependence on a value existing in the form that called it.
I thought it would be neat to provide an openargs string in the format,
key=value;key=value;.... etc
And then on the opening form side just use a function like this:
Then you would run something like..
I have several questions - first of all, why do I get a compile error saying 'argument not optional', pointing at the "arguments = getArguments(argsString)" line..
And, has anyone come up with something like this before, and could you share it with us?
Thanks all.
Hi there,
I want to develope a robust way of being able to pass arguments to a form when opening it. This way, I can treat the form basically like a function - and it severs the opening forms usual dependence on a value existing in the form that called it.
I thought it would be neat to provide an openargs string in the format,
key=value;key=value;.... etc
And then on the opening form side just use a function like this:
Code:
Function getArguments(ByVal optArgs As String) As Dictionary
Dim dict As Dictionary
Dim temp As String
temp = Split(optArgs, ";")
For Each kvp In temp ' Iterate through each element.
Dim temp2 As String
temp2 = Split(kvp, "=")
dict.Add temp2(0), temp2(1)
Next
getArguments = dict
End Function
Then you would run something like..
Code:
Private Sub Form_Open(Cancel As Integer)
argsString = OpenArgs
Me![args] = argsString
Dim arguments As Dictionary
arguments = getArguments(argsString)
If arguments.Exists("new") Then
If arguments.Item("new") = "true" Then
'open form in new mode
End If
Else
'look for item_id and filter for it
End If
End Sub
I have several questions - first of all, why do I get a compile error saying 'argument not optional', pointing at the "arguments = getArguments(argsString)" line..
And, has anyone come up with something like this before, and could you share it with us?
Thanks all.
Last edited: