Call A Subroutine in The Parent Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have code in the Parent Form to respond to "PageUp"
& "PageDown" keys....works fine.

However, I want to call that code sometimes when the Focus is on a
Subform.

How do I call it???

This is NOT working..

---This is in the Subform ---The Parent Form is "frmMain"
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call Forms.frmMain.Form_KeyDown(KeyCode, Shift)

TIA - Bob
 
Bob Barnes said:
I have code in the Parent Form to respond to "PageUp"
& "PageDown" keys....works fine.

However, I want to call that code sometimes when the Focus is on a
Subform.

How do I call it???

This is NOT working..

---This is in the Subform ---The Parent Form is "frmMain"
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call Forms.frmMain.Form_KeyDown(KeyCode, Shift)

That ought to work if you change the declaration of the Sub on the
*parent* form from

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

to

Public Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

In the subform, you could simplify your call to the routine in the
parent form by writing it as

Call Me.Parent.Form_KeyDown(KeyCode, Shift)
 
Dirk _ thank you.

That SHOULD work, but I get Error 2465..."Application-defined
or object-defined error"

Any idea why?

TIA - Bob
 
Bob Barnes said:
Dirk _ thank you.

That SHOULD work, but I get Error 2465..."Application-defined
or object-defined error"

Any idea why?

TIA - Bob

Hmm, it works for me. Are you sure you changed the declaration of the
event procedure on the parent form, from "Private Sub" to "Public Sub"?
I find that if I don't do that, I get the error message you describe.
 
Bob Barnes said:
Dirk - You are Correct.

Making the 2 Subs Public in the 2 Forms WORKS.

Thank you - Bob

You're welcome. Note: the procedure in the subform doesn't have to be
Public, since it won't be called from outside that form. Only the
parent form's event proc has to be Public.
 
Back
Top