Call A Subroutine in The Parent Form

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
 
D

Dirk Goldgar

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)
 
G

Guest

Dirk _ thank you.

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

Any idea why?

TIA - Bob
 
D

Dirk Goldgar

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.
 
G

Guest

Dirk - You are Correct.

Making the 2 Subs Public in the 2 Forms WORKS.

Thank you - Bob
 
D

Dirk Goldgar

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.
 

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