how to call current event procedure of from from subfrom (1 Viewer)

masoud_sedighy

Registered User.
Local time
Yesterday, 16:04
Joined
Dec 10, 2011
Messages
132
i have a main form and it's name is:[frmTranstoCon-vp_New]

and this main form has a continuous subform and it's name is:[fsubTranstoConDoc-vp_New]

now i want after click one button from a subform i call the current event procedure of main form, i have done it in several ways but i got error:

"Application defined or object defined error"


what i have done for calling current event procedure of main from from it's subform is like below:

1- Forms![frmTranstoCon-vp_New].Form_Current

2- Me.Parent.Form_Current
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:04
Joined
May 7, 2009
Messages
19,229
The Current event is Private sub, mske it Public, by editing the declaration.
 

masoud_sedighy

Registered User.
Local time
Yesterday, 16:04
Joined
Dec 10, 2011
Messages
132
thank you very much, it works now
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:04
Joined
May 7, 2009
Messages
19,229
You are welcome.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:04
Joined
Jul 9, 2003
Messages
16,273
It's not considered good practice to call an object event directly. Also, it is unnecessary, all you do is put the code that currently resides in the on current event in its own function or sub procedure and call that.

This is a very good example of why this approach would be better. In this example you are protecting the private on current event. In other words, it is unnecessary to make the on current event public, all you do is make the new function or subroutine public.
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 00:04
Joined
Sep 21, 2011
Messages
14,238
Oops, I have done that a few times, but so far always from within the same form.

Eg I set a checkbox on load then call it's click event.

It's not considered good practice to call an object event directly. Also, it is unnecessary, all you do is put the code that currently resides in the on current event in its own function or sub procedure and call that.

This is a very good example of why this approach would be better. In this example you are protecting the private on current event. In other words, it is unnecessary to make the on current event public, all you do is make the new function or subroutine public.
 
Last edited by a moderator:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 00:04
Joined
Jul 9, 2003
Messages
16,273
Oops, I have done that a few times, but so far always from within the same form.

Eg I set a checkbox on load then call it's click event.

I think everybody does things like this when they are developing, I certainly do!
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:04
Joined
Feb 19, 2002
Messages
43,233
I agree with Uncle. Common code should always be stored in a standard module. If you need the code to reference form fields, pass in a reference to the current form. Sometimes I know ahead of time that what I am writing will be useful in other situations so I start out with it separated. Sometimes, the app changes and I find that I need to reuse code. As soon as that happens, I copy it from where it was into a separate procedure and replace the code in the original spot with a call to the new procedure. That makes it completely obvious that the code has other uses. This head's up will save your bacon some day when you have to make a change to the code. You won't make the mistake of breaking another procedure.
 

Users who are viewing this thread

Top Bottom