Running Public Sub in parent form from child form

cpampas

Registered User.
Local time
Yesterday, 16:47
Joined
Jul 23, 2012
Messages
221
I wonder if this is posible !
Can I run a Main form button's Public Sub , from the child form ?

Code:
str = "AAA"
[Forms]![frmMagicCont]![Procura de Documentos].[Form]![Descritivo] = str   ' this parts works fine
Call Forms([frmMagicCont]![Procura de Documentos]).Command68_Click     ' this part does not
 
Try
Code:
Call Me.Parent.Command68_Click
Are you sure that even has been changed to Public?, as it defaults to Private?
 
Call Me.Parent.Command68_Click
Yes, I changed it to Public
That would work if the button was in the parent form, but (my mistake), Actualy the title in my post is incorrect since the sub to be runned is not in the parent form(frmMagicCont), but rather in the first child ([Procura de Documentos]) form, and i will be calling it from another second child form
 
Me.Parent.subformcontrolname.Form.methodname
 
Personally I prefer to have the Private button code and a Public Sub (aka Method) run the same code rather than making the button code Public.
 
Me.Parent.subformcontrolname.Form.methodname
I'm trying different combination, but I keep receiving Application-defined error.

Subform Name: frmParts_Sub
parent Name : frmProcess

I'm trying to run cmdShowDrawing_Onclick() in parent by double clicking a text box in subfrom. Textbox name is txtDr.

What would be the exact code to run cmdShowDrawing_Onclick() in parent form?
thank you.
 
The parent name doesn't matter. Parent is a Property of a control that refers to the parent object.

Note the subform object might not have the same name as the subformcontrol that holds it though it is by default.

If the method is in a subform on the parent:
Code:
Me.Parent.frmParts_Sub.Form.cmdShowDrawing_OnClick

If in the parent:
Code:
Me.Parent.cmdShowDrawing_OnClick

Or maybe:
Code:
Me.Parent.Form.cmdShowDrawing_OnClick

(Its Friday night and been a hard week.)
 
Just on a general point, you wouldn't want to design a subform to run code in the parent form, I don't think. The subform ought to know about itself only. What code are you trying to run in the parent?
 
you wouldn't want to design a subform to run code in the parent form. The subform ought to know about itself only.
I don't see any particular reason why not. I've done forms that reconfigure themselves into a more compact layout when they detect they are inside a Parent form.
 
the sub cmdShowDrawing_Onclick()
must be declared Public Sub(not Private)
 
I don't see any particular reason why not. I've done forms that reconfigure themselves into a more compact layout when they detect they are inside a Parent form.
I was thinking more of a data management point of view, but I see what you mean.
 
Just on a general point, you wouldn't want to design a subform to run code in the parent form, I don't think. The subform ought to know about itself only. What code are you trying to run in the parent?
I don't. I was just testing. OP was able to run the code and my tests brought up errors.
I was just curious why or where I'm making the mistakes.

Seems that as @arnelgp suggests, the sub should be declared as public and not private.
 
the sub cmdShowDrawing_Onclick()
must be declared Public Sub(not Private)
From FormA, I can run a control's event procedure on FormB's. Even if it's private.

Forms("FormB").cmdTest_OnClick

Why when I try to run a code in parent form from it's child form, it should be public?

thanks
 
Keep in mind that when you run code on a subform, it operates on what Access thinks is the current record so make sure you know what that is.
 
All code using _OnClick() needs to be replaced with _Click without the () brackets e.g. CmdShowDrawing_Click
 

Users who are viewing this thread

Back
Top Bottom