Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing alternative OpenArgs to Access Forms created with 'New'

The Scenario: I tried to use this code to create an alternative OpenArgs property according to the suggestion of Rubberduck, but I cannot get this to work. I guess I'm missing something here, but have no idea what.

The Code:

Public varAltOpenArgs As Variant
Dim FormX as form

Public Property Let AltOpenArgs(value As Variant)
    varAltOpenArgs = value
End Property

Public Property Get AltOpenArgs() As Variant
    AltOpenArgs = varAltOpenArgs
End Property

A new instance of the form is opened from this form (form1) using:

Set frmX = New 
frmX.AltOpenArgs = "abcde"
frmX.SetFocus

The problem: The property AltOpenArgs contains an empty string ("") when called in Form_Open.

Can anybody point me in the right direction? I'm using Access 2010 (32).

like image 560
Art Avatar asked Nov 09 '22 10:11

Art


1 Answers

The problem is, all the events are firing as soon you create the new instance (Set frmX = New Form_MyExampleForm) before your next line of code runs where you set the value of AltOpenArgs.

This will never work because Access forms are made to be Instantiated by the Application and you don't really have control over the events. If you absolutely can not use the built in OpenArgs, then you could do something like this where you are running a routine from the Property Let:

Public Property Let AltOpenArgs(value As Variant)
    varAltOpenArgs = value
    FancyRoutine
End Property

Private Sub FancyRoutine() 
    'Do whatever fancy stuff you want to do
    MsgBox AltOpenArgs
End Sub

I do something along the lines of what you are trying (though not using the Form_Open event) for subforms. It might look like this:

Dim frm As Form_MyExampleForm
Me.SubformControl.SourceObject = "MyExampleForm"
Set frm = MainSubform.Form
frm.AltOpenArgs = "whatever you want"
like image 191
Don Jewett Avatar answered Nov 14 '22 22:11

Don Jewett