Referencing a parent form

dsmaj

Registered User.
Local time
Today, 13:34
Joined
Apr 28, 2004
Messages
96
I currently have a frm_Initiative form which loads a frm_Jurisdiction form in order to collect information that will subsequently be put into some textboxes on the frm_Initiative form. I want to use the parent object within frm_Jurisdiction because there will be a few different forms calling frm_Jurisdiction, which will all need to receive the same information from it (in textboxes all with the same name). I'm using the following line of code within frm_Jurisdiction to try and reference the parent:

Me.Parent!txtJurisdiction.Value = txtJurisdictionName.Value

...however it is resulting in Runtime error 2452: "The expression you entered has an invalid reference to the Parent property."

I have tried several variations of the above code, all with the same result. Any ideas what the problem might be?

Thanks in advance,
Sam
 
A parent form is the form which contains the current subform. Is that how you're trying to use the Parent object? It sounds from your description like they are all separate forms.
 
dcx693 said:
A parent form is the form which contains the current subform. Is that how you're trying to use the Parent object? It sounds from your description like they are all separate forms.

I think I may be using the Parent object incorrectly. You're reading my post correctly--I'm trying to access (relatively) the form from which the current form was called (they are both two completely different forms), is there a way I can do this?

Thanks,
Sam
 
There is no built-in way for a form to recall how it was opened. You'll need to build something in your database for it. A typical easy way is to use the OpenArgs property of the form. When you open a form using VBA code, you use the DoCmd.OpenForm method. The method has several arguments including one called "OpenArgs". It's used to pass opening argument information to the form you are opening. So for example:
Code:
DoCmd.OpenForm "frmSecondForm",  ,  ,  , , , Me.Name
would pass the name of the form running that code to the form called "frmSecondForm".

From within that frmSecondForm form, you can use code like to use the value that was passed:
Code:
If Me.OpenArgs="frmFormOne" Then
    ' do this
Else
    ' do something else
End If
 
dcx693 said:
There is no built-in way for a form to recall how it was opened. You'll need to build something in your database for it. A typical easy way is to use the OpenArgs property of the form. When you open a form using VBA code, you use the DoCmd.OpenForm method. The method has several arguments including one called "OpenArgs". It's used to pass opening argument information to the form you are opening. So for example:
Code:
DoCmd.OpenForm "frmSecondForm",  ,  ,  , , , Me.Name
would pass the name of the form running that code to the form called "frmSecondForm".

From within that frmSecondForm form, you can use code like to use the value that was passed:
Code:
If Me.OpenArgs="frmFormOne" Then
    ' do this
Else
    ' do something else
End If

Brilliant! So simple and effective. I can't believe I didn't think of it :confused:

Thanks a lot!
Sam
 

Users who are viewing this thread

Back
Top Bottom