Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Calling sub routines

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Calling sub routines

Call Userform1.Print_Report

--

HTH

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


"Andrew" wrote in message ...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calling sub routines

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


"Andrew" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - sub routines Help please Richard Wrigley New Users to Excel 3 November 23rd 06 03:06 AM
VBA routines - help please Richard Wrigley Excel Discussion (Misc queries) 1 November 22nd 06 07:15 PM
vb dummy - two routines Greg Excel Programming 6 June 20th 05 04:56 PM
Removing VBA routines Robin Clay[_2_] Excel Programming 2 October 14th 03 05:44 PM
api call routines anthony Excel Programming 2 July 21st 03 02:00 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"