Calling sub routines

A

Andrew

I have a userform with a sub-routine "under" it that I want to call from a routine under another userform within the same project. I changed the called routine title from Sub to Public Sub having read some of the previous posts on a similar topic but I seem to be missing the plot somewhere.

UserForm1
Private Sub cmdPrint_Click()
Call Print_Report

Public Sub Print_Report()

...... this works


UserForm2
Private Sub cmdPrint_Click()
Call Print_Report

...... this doesn't work

I cant put the Print_Report() routine in the Modules section because it pulls values from the forms. I guess there is a way to get over that problem as well but I thought the first fix would be the easiest to discuss.

Thanks for your help in advance.
Andrew
 
B

Bob Phillips

Call Userform1.Print_Report

--

HTH

RP
(remove nothere from the email address if mailing direct)


I have a userform with a sub-routine "under" it that I want to call from a routine under another userform within the same project. I changed the called routine title from Sub to Public Sub having read some of the previous posts on a similar topic but I seem to be missing the plot somewhere.

UserForm1
Private Sub cmdPrint_Click()
Call Print_Report

Public Sub Print_Report()

..... this works


UserForm2
Private Sub cmdPrint_Click()
Call Print_Report

..... this doesn't work

I cant put the Print_Report() routine in the Modules section because it pulls values from the forms. I guess there is a way to get over that problem as well but I thought the first fix would be the easiest to discuss.

Thanks for your help in advance.
Andrew
 
T

Tom Ogilvy

You can put the Print_Report code in a general module

You should probably alter it to receive a reference to the form calling it
as an argument

then it can pick up the values it needs from the form

UserForm1
Private Sub CmdPrint_Click()
Print_Report Me
End Sub
---------------------------
UserForm2
Private Sub CmdPrint_Click()
Print_Report Me
End Sub
---------------------------
General module
Public Sub Print_Report(form)
MsgBox form.Label1.Caption
End Sub


--
Regards,
Tom Ogilvy


I have a userform with a sub-routine "under" it that I want to call from a
routine under another userform within the same project. I changed the
called routine title from Sub to Public Sub having read some of the previous
posts on a similar topic but I seem to be missing the plot somewhere.

UserForm1
Private Sub cmdPrint_Click()
Call Print_Report

Public Sub Print_Report()

...... this works


UserForm2
Private Sub cmdPrint_Click()
Call Print_Report

...... this doesn't work

I cant put the Print_Report() routine in the Modules section because it
pulls values from the forms. I guess there is a way to get over that
problem as well but I thought the first fix would be the easiest to discuss.

Thanks for your help in advance.
Andrew
 

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