calling methods of a form from another

G

Guest

Why some times calling subform [or master form] public methods from inside
form works, and other times it gives runtime error 2455 "You entered an
expression that has invalid reference to the Property Form"

Private Sub aMainFormEventProcedure()
Me.subformName.Form.methodNameInSubform
End Sub
 
M

Marshall Barton

elburze said:
Why some times calling subform [or master form] public methods from inside
form works, and other times it gives runtime error 2455 "You entered an
expression that has invalid reference to the Property Form"

Private Sub aMainFormEventProcedure()
Me.subformName.Form.methodNameInSubform
End Sub


The most common reasons for that is when the name of the
subform control is different from the name of the form
object it is displaying. You must use the name of the
subform control.

Another reason is when the method is called before the
subform has completed its opening processing.
 
G

Guest

Marshall Barton said:
elburze said:
Why some times calling subform [or master form] public methods from inside
form works, and other times it gives runtime error 2455 "You entered an
expression that has invalid reference to the Property Form"

Private Sub aMainFormEventProcedure()
Me.subformName.Form.methodNameInSubform
End Sub


The most common reasons for that is when the name of the
subform control is different from the name of the form
object it is displaying. You must use the name of the
subform control.

Another reason is when the method is called before the
subform has completed its opening processing.

Thank you for replying. my procedure is actually:
Private Sub Form_Current()
Me.subformName.Form.methodNameInSubform
End Sub
So; the subform has not opened yet, after form open and Form_Current() is
called. I want methodNameInSubform() to be called when main form [plus its
subforms] have openend; also be called everytime I browse to another record
(click left or right navigation buttons). Is Form_Current() the right event
to code? If so; would this do what I want:
Private Sub Form_Current() 'in main form
If <subforms are open>
Me.subformName.Form.methodNameInSubform
End Sub

Private Sub Form_Open() 'in subform (to run once the first time)
Me.Form.methodNameInSubform
End Sub
 
M

Marshall Barton

Since, unlike reports, subforms are opened before the main
form, the main form can call the subform's methods in any(?)
event. However, subforms can not call a main form method in
their Open, Load or first Current event. It gets very
tricky if you should want to call one subform's method from
a different subform's Open, Load or first Current events.
The reason I keep saying first Current event is it seems to
occur right after the Load event.

You can check the order of all these events by placing
Debug.Print Me.Name & ": name of event" in each form's Open,
Load and Current events.

I think I might need to emphasize that the name of the form
being displayed as a subform is not releveant. You get to
the form through the subform **control** (Access will figure
out which form is being displayed in the control by looking
at the subform control's SourceObject property). While
Access might name them the same, they may very well be
different. Your generic call should be:

Me.subformControlName.Form.methodNameInSubform
--
Marsh
MVP [MS Access]

Marshall Barton said:
elburze said:
Why some times calling subform [or master form] public methods from inside
form works, and other times it gives runtime error 2455 "You entered an
expression that has invalid reference to the Property Form"

Private Sub aMainFormEventProcedure()
Me.subformName.Form.methodNameInSubform
End Sub


The most common reasons for that is when the name of the
subform control is different from the name of the form
object it is displaying. You must use the name of the
subform control.

Another reason is when the method is called before the
subform has completed its opening processing.

Thank you for replying. my procedure is actually:
Private Sub Form_Current()
Me.subformName.Form.methodNameInSubform
End Sub
So; the subform has not opened yet, after form open and Form_Current() is
called. I want methodNameInSubform() to be called when main form [plus its
subforms] have openend; also be called everytime I browse to another record
(click left or right navigation buttons). Is Form_Current() the right event
to code? If so; would this do what I want:
Private Sub Form_Current() 'in main form
If <subforms are open>
Me.subformName.Form.methodNameInSubform
End Sub

Private Sub Form_Open() 'in subform (to run once the first time)
Me.Form.methodNameInSubform
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top