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).
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With