Robust solution to allowing easy passing of arguments to forms

hiero

New member
Local time
Today, 09:05
Joined
Nov 23, 2003
Messages
5
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:

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:
I had a similar problem. My solution was to set variables in a module that i called something like commonVariables, and then i just checked the variables i needed to determine things on form load. Not sure where your method is going wrong, but you might be able to fix it by putting Optional front of the parameter
 

Users who are viewing this thread

Back
Top Bottom