call a sub

  • Thread starter Thread starter tzcarmy
  • Start date Start date
T

tzcarmy

Guest
hi
Can anyone tell how can i CALL a sub that exist on sun form, from then father form???? (on VBA code)
thanks for any help!
 
in the Father form where you want the code put in:

Call subForm.SubYouWantToCall(AnyVariables)

replace subForm with the name of the subform, and SubYouWantToCall with the sub you want to call, replace AnyVariables with the variables that the sub you are calling requires.

Hope this helps and I haven't confused you to much.

-YK120
 
An FYI for clarity's sake:

What you call "father" is known by most as "Parent"

And what you called "sun (sic)" is known by most as "Child"
 
Also, the sub needs to be public in order to reference it via the form class.
 
Thank's for the replys!

I'ii try the way "yk102" offer, hope it will work.
I want to thank you all, i learn a lot from your answers!
 
it dosn't work...

In the Child form i have a sub:

Public Sub XXX()
MsgBox "Test", ""
End Sub

I try to call it from the father form:

Private Sub cmdPaste_Click()
Call [Database].XXX
End Sub

I got this error message:
"method or data member not found"

any idea????
Thank's
 
Last edited:
There may be a way to call a sub, other than a form event, from a parent form, but the easiest way is to stick the sub into a Module and mark it public. Then, you can call it from any form.
 
If the subform is open:

Forms!frmMain![frmSubForm].Form.ThatSubOrFunction

Where ThatSubOrFunction is Public.

Wayne
 

Users who are viewing this thread

Back
Top Bottom