Run a module from command button or macro

D

Daivd

How are modules run in Access. I know this sounds like a
silly question, but the only way I've been able to do this
so far is by opening the module in the VBA editor and
clicking run.

Surely I can execute this from a command button or macro,
but I don't know what I'm missing.

Also, does it matter if the module is private?

Regards,

David
 
R

Rick Brandt

Daivd said:
How are modules run in Access. I know this sounds like a
silly question, but the only way I've been able to do this
so far is by opening the module in the VBA editor and
clicking run.

Surely I can execute this from a command button or macro,
but I don't know what I'm missing.

Also, does it matter if the module is private?

You don't run modules. What you run are the sub-routines and functions
that are contained in your modules.

So if you have a module that contains a non-private sub named
"GetDataAndDoSomething" you could use code anywhere in your app to run that
with the statement...

Call GetDataAndDoSomething

If the sub were private then only code in the same module could call it.

You can also use a Macro with the RunCode Acton, but I think that only
works for functions. A sub can easily just be changed to a Function though
and then it would work.

If you create functions in your module(s) you can use them in controls and
queries just as if they were built in functions.
 
V

Van T. Dinh

Well ... no, you can't run a Module. Modules are simply "containers" that
contain the codes.

You can execute Procedures contained in the Modules.

To execute a VBA Function (NOT Sub) in Macros, you use the RunCode action.

To execute a Sub or a Function, you can use the Call statement in the
CommandButton_Click Event.

Suggest you check out an Access book as most Access books cover these basic
concepts which you need to do more complex stuff.
 

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