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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute a second subroutine from within a main subroutine 2

Status
Not open for further replies.

rew2009

Technical User
Apr 21, 2009
114
US
I need to execute a second subroutine from within a main subroutine something like the following but I know that the form or syntax is not right. What would be the correct code?


Private Sub Command307__Click()

Private Sub Command308_Click()

End Sub

Thanks Russ
 
It's better practice to call a Sub/Function that does the coding that you have in the Command308_Click() event. You can then call that sub from the Command308_Click() event as well.

This not only makes you code more portable it also makes it infinitely more readable.

Hope this helps

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
In the VBA help have a look at the Call instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'm sorry, I am not quite following. I think you are saying that I run the Command308__Click() event from itself.

However, I have to execute the Private Sub Command307__Click() event but want to run the code in the Command308__Click() . Could you clarify? Thanks Russ
 

You don't include the "Private Sub" part when calling the second sub:

Private Sub Command307__Click()
Command308_Click()
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
What I mean is you create a Sub/Function that holds the code you currently have in the Command308_Click() event e.g.
Code:
Sub MyNewSub
MsgBox "Hello"
End Sub
You can now call that sub from both your command buttons rather than forcing a click event.

Hope this makes sense.

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
I now understand both ways of doing it. Thanks Guys, Russ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top