How to pass Arguments to New Instance of a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I create a new form instance using

Set frm = New Form_formname

When 'formname' opens I want to know who opened it so that I can make
certain controls visible.

Normally I would use DoCmd.OpenForm..."argument" to pass info to the form.

How is the equivalent achieved in a new instance situation.
 
hi Thomas.
I create a new form instance using
Set frm = New Form_formname
When 'formname' opens I want to know who opened it so that I can make
certain controls visible.
Normally I would use DoCmd.OpenForm..."argument" to pass info to the form.
How is the equivalent achieved in a new instance situation.
Use a public init procedure:

Set frm = New Form_formname
frm.Init Args


Your form code:

Public Sub Init(AArgs As Variant)

If Not IsNull(AArgs) Then
Else
End If

End Sub

Public Sub Form_Open

Init OpenArgs 'To get the same behaviour with DoCmd

End Sub


mfG
--> stefan <--
 
Could someone explain this a little more. I need to do the same thing, but I
don't understand the example that was given.

Thanks!
 
hi Sandy,
Could someone explain this a little more. I need to do the same thing, but I
don't understand the example that was given.
Take a look at DoCmd.OpenForm. It has a parameter OpenArgs. You can use
this parameter to control e.g. what do display on your form:

DoCmd.OpenForm "frmUser",,,,,"Edit"

This parameter can be evaluated in the Form_Open method, e.g.

Privat Sub Form_Open()

Me.AllowEdit = (OpenArgs = "Edit")

End Sub


As DoCmd.OpenForm cannot work with multiple instances of a form, you
need a workaround:
a initialization procedure, you can pass control information to your new
instance.
Another way would be a so-called factory (see Wikipedia for programming
patterns). But this is to much overhead for an Access application.

The additional Init OpenArgs in my example is just a redirection to the
initialization method, when someone uses the
DoCmd.OpenForm "frmUser",,,,,"Edit" approach.



mfG
--> stefan <--
 
Hi Stefan,

I tried this solution, but alas The Form Open and Form Load are occurring
before the init. Apparently Form Open and Form Load occur during

Set frm = New Form_formname

Thus, unlike with openargs, you cannot use this solution during that stage.

Tom M.
 
Back
Top