Passed Form's property "gone empty" between Property LET and GET (1 Viewer)

Noruen

Member
Local time
Today, 21:29
Joined
Jul 7, 2020
Messages
46
Hi!

I'm trying to create by-pass of OpenArgs for my form as I want to use form instances and OpenArgs is read-only + new instances cannot be created using DoCmd.OpenForm.

I have read through various forums how to pass this alternative OpenArgs to new form instance so I created in Form's module (that form I want to create various instances of...):

Code:
Option Compare Database
Option Explicit

Dim strOpenArgsAlt As String

Public Property Let OpenArgsAlt(InputArgs As String)
    strOpenArgsAlt = InputArgs
End Property

Public Property Get OpenArgsAlt() As String
    OpenArgsAlt = strOpenArgsAlt
End Property

I'm successful with passing my OpenArgsAlt from another form (Debug.print in LET property sucessfuly prints value I passed), however when I want to use Property in form's Form_Open event, both OpenArgsAlt Property but also strOpenArgsAlt variable appears empty.

Do you have any idea what I'm doing wrong?

Many thanks guys!
 

jdraw

Super Moderator
Staff member
Local time
Today, 15:29
Joined
Jan 23, 2006
Messages
15,379
Can you give us a description/example of your proposed usage of this? Form Instances?
 

Noruen

Member
Local time
Today, 21:29
Joined
Jul 7, 2020
Messages
46
Can you give us a description/example of your proposed usage of this? Form Instances?
Sure!

I have forms that i use to search IDs for another form. Like Search Category, Search Vendor, etc.

Now I use DoCmd.OpenForm ... , "Field:cboCategoryID;Form:frmExampleForm" (OpenArgs): i parse OpenArgs string to use target form and field to pass searched value, like:

Code:
Forms(strTgForm).Form.Controls(strTgField).Value = Me.lstVendors

However sometimes I need to open this form twice (Categories have several relationships) and as I cannot open another form instance, i need to by-pass it.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:29
Joined
May 7, 2009
Messages
19,245
you can just create a "hidden" textbox to your form (say, tOpenArgs).

you can pass the value to this textbox:

dim f as Form
set f = Form_YourFormName
f!tOpenArgs = 1 'or any value you can pass
f.Visible = True

now before this edit "YourFormName" form and add Code to it's Timer Event,
and set the Timer to 100 (ms).
this is a sample:


Private Sub Form_Timer()
Me.TimerInterval = 0
If Not IsNull(Me.tOpenArgs) Then
MsgBox Me.tOpenArgs
End If
End Sub

you will see that it will msg what is in Me.tOpenArgs textbox, which is number 1.
 
Last edited:

Noruen

Member
Local time
Today, 21:29
Joined
Jul 7, 2020
Messages
46
@arnelgp o_O so simple... and I spent half a day trying to solve it... Thanks!

Anyway... do you have any idea why code above didn't work?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:29
Joined
May 7, 2009
Messages
19,245
do you have any idea why code above didn't work?
i can only guess, that on New instance of your form, all variables are not set yet.
 

Noruen

Member
Local time
Today, 21:29
Joined
Jul 7, 2020
Messages
46
@arnelgp sure, but I know that when I pass frm.OpenArgsAlt = “something”, new instance will get that value in LET property, however after that it is lost, for some reason :/
 

ebs17

Well-known member
Local time
Today, 21:29
Joined
Feb 7, 2020
Messages
1,949
Code:
Private m_loa As Long

Public Property Get oa() As Long
    oa = m_loa
End Property

Public Property Let oa(ByVal loa As Long)
    m_loa = loa
End Property
You get something like this if you convert a public variable into a property using MZTools, for example. The property is to be added to the code of the form class.

To test availability, the form module is supplemented with the following procedure:
Code:
Public Sub Show_oa()
    MsgBox Me.oa
End Sub

Now a call from the outside is missing. As you can see, the Form_Open event doesn't matter. The instance of the form is initialized and the argument is passed to the Let property. This makes the argument available in the form.
Code:
Dim frmA As Form_frmXY

Sub test_property()
    Set frmA = New Form_frmXY
    frmA.oa = 77
    frmA.Visible = True
    frmA.Show_oa
End Sub
And finally: If you now define your own properties in the form, forget about the universal helper property OpenArgs.
 

Noruen

Member
Local time
Today, 21:29
Joined
Jul 7, 2020
Messages
46
@ebs17 Thanks! you saved me! So the problem is the property is not immediately available after the form loads. I tested your approach and it work now. Amazing, thanks a lot!
 

Users who are viewing this thread

Top Bottom