Calling a Module from Switchboard

  • Thread starter Thread starter LJG
  • Start date Start date
L

LJG

Hi Guys,

Just wondering if any one knows how I can call a module from the switch
board?

I have a module with a number of functions that I want to run one after the
other once the button is clicked. From the switchboard manager I can call a
function but do not seen to be able to call a module.

Can anyone help, I am missing something really simple here?

TIA

Les
 
LJG said:
Hi Guys,

Just wondering if any one knows how I can call a module from the
switch board?

I have a module with a number of functions that I want to run one
after the other once the button is clicked. From the switchboard
manager I can call a function but do not seen to be able to call a
module.
Can anyone help, I am missing something really simple here?

Runnable VBA code is either in a function or a sub-routine. You cannot "run a
module" as a module is just the container for functions and subs. I suspect
what you meant to say was "sub-routine" and you're correct that in many contexts
only functions can be called, not sub-routines.

The simplest solution is to simply change your sub into a function. It only
takes a few keystrokes and it won't change how the code is run or how it might
currently be getting called in other places. There are some developers who
write all their code as functions for this reason.
 
You don't "run" a module.

A module usually contains many functions and subs. Those subs + functions
are normally "grouped" together by you the developer.

Fro example, I have the following modules in one of my palpations:

Module name purpose
api Most of my windows api code is here
FileOpenApi File open/dialog browse code.
locks My custom locking code
ReLink Code to re-link tables on startup
Security All of my security manager code.
WordCode All of my code for word.


In each of the above modules, you don't "call" the module, but you call code
*inside* each of the modules.

So, for the WordCode module, there is bunch of code and routines that the
word merge code uses. Of course, this means that the subs (or functions)
inside of these modules has to have a different name then the module.
I have a module with a number of functions that I want to run one after the
other once the button is clicked.

If those functions don't return values, then you should be use subs.....

You can't call the module, but you can certainly call the subs, and
functions inside.

eg:

Call MySub1
Call Mysub2

And, if you have functions that don't return values, you can go:

MyfunctionName1
MyFunctionName2

etc.....

You could even I suppose build a sub, and place it in the module..and it
could call all of the code/routines inside.

So, you don't call a "module". A module is a nice grouping of code that you
create. You can in theory place ALL of your routines in ONE module, but as
you can see in my example above, I have a number of "modules" that help
developers "group" their code into sections. This grouping is entirely up to
you the developer. However, you can make routines PRIVATE to a particular
module, and then that means that ONLY that module can call/use that code.
(again for grouping and reasons of maintains we do this). Also, we might
want some routines to ONLY be used by a particular module.

So, you don't call a module!!!

Of couse, if we are talking about a class module, then that is a bit
differnt, as in that case, you actually use a "instance" of the module!!
 
Doh!!....always an easy way....thanks

Les




Allen Browne said:
Why not create a master function that calls the others, e.g.:

Function Main()
Call MyFirstFunction()
Call MyOtherFunction()
Call SomethingElse()
'etc.
End Function
 
Why not create a master function that calls the others, e.g.:

Function Main()
Call MyFirstFunction()
Call MyOtherFunction()
Call SomethingElse()
'etc.
End Function
 

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

Back
Top