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!

How can I run a module from a command button?

Status
Not open for further replies.

MalcolmJ

Programmer
Mar 10, 2004
2
0
0
IE
The only way that I've able to run a module is by clicking the RUN button. If I try to run the module from another module, the code is displayed on the screen, but, it does not execute. What does it take to make it run automatically.
 
To run a function from a module when you click a command button, you can use the code Call FunctionName()

This is the same as using a macro and the RunCode action.
 
A module is essentially a container for functions and subroutines. If a module contains one or more functions/subroutines that are public (i.e. Public Function abc()) then you can call them:

Function call:

Answer = abc()

Subroutine call:

Zero parameter
SubName

One parameter
SubName(ParaOne)

More parameters
Call SubName(ParaOne, ParaTwo)

Steve King

Growth follows a healthy professional curiosity
 
Hello Steve,

This is a long dead thread , but I am desperate about finding a way to run a module (just one subroutine ) from a Macro. I tried all sort of variations on your suggestions, but every time I run into a message that the function does not exist. But there is no function , it is just one public Sub in the VBA code. Where should I make the call from the macro ...............??? T. Blom
Information analyst
tbl@shimano-eu.com
 
Well, I don't generally use macros, but if my memory serves me correctly you can NOT run a subroutine from a macro. Change the subroutine to a function and give it a try. I believe a macros exists called RunCode. Just remember that any other normal calls to the subroutine would be affected by this modification so check it out by opening the module (you need to do this to make the change anyway) and compiling it.

e.g. Change "Public Sub RoutineName" to "Public Function RoutineName".

-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Thanx Steve,

I changed the subroutine to function and can now run it with the runcode in a macro.... T. Blom
Information analyst
tbl@shimano-eu.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top