Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a procedure held in a form from another form

Status
Not open for further replies.

iamthebestuk

Technical User
Jan 31, 2005
48
0
0
GB
Hi,

I'm trying to call a procedure stored in a form from another form. I have made both procedures public subs but get an error message when executing this code:

Call cmdExportToExcel_Click

Is someone able to help?

Thanks,
Bhavesh



Power is Knowledge
Knowledge is Power
 
you should make a module for this code, and call that from both forms...

if you try to call one forms functions from another form, you need to make sure that the form with the function is open and you need to prefix the function with forms!formName!functionName...

--------------------
Procrastinate Now!
 
if you try to call one forms functions from another form, you need to make sure that the form with the function is open and you need to prefix the function with forms!formName!functionName..

Not actually a true statement. If you use the forms collection , yes, but not if you use the forms class.

If the procedure is public

Public Sub Command0_Click()
MsgBox Me.Name
End Sub

Then you can simply call this procedure using the form class

call form_YourFormName.Command0_Click

You may want to keep the original procedure Private, in that case give it a wrapper.

Private Sub Command0_Click()
MsgBox Me.Name
End Sub

Public Sub callCommand0_Click()
Command0_Click
End Sub

From Outside
call Form_Form1.callCommand0_Click



Public Sub callCommand0_Click()
Command0_Click
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top