KBV - What's the difference between a module and a macro?

  • Thread starter Thread starter Guest
  • Start date Start date
A macro is a series of instructions that ms-access can execute.

A module is a place where you can put in VBA code. The other difference is
that you cannot run a module, but you can run a macro.

However, you can most certainly run code that is placed into a module.
 
Thank you - one more question, if you can't run a module, how exactly do you
get it to execute the VBA code that you write?
 
Modules contain Functions or Subroutines.
You call them to run the code.

And, Forms and Reports have associated Modules in which you can place code
that is executed when particular Events occur (such as the OnCurrent event,
which executes for each different record that is displayed, or the Open
event, which executes when the Form is opened). It is most often from this
"event code" that Functions and Sub Procedures in standard Modules are
called, but they can also be called from Macros, using the RunCode step in
the macro.

Larry Linson
Microsoft Access MVP
 
Thank you - one more question, if you can't run a module, how exactly do
you
get it to execute the VBA code that you write?

Well, you have a few answers already.

To run code in a module, you can

* Call the code from a button on a form (the on-click code can call code
in the module)

* You can place your cursor in the code in the module and hit f5 to run

* you can type in the debug window

Call NameOfYourSubInModule

So, any button you build can call the code. You can also manually run the
code as above from the debug window.

And, of couse one of the many "events" that a form or even a text box has
can also call code in a module.
 
Another difference is that macros are easier to understand and work
with from a beginners viewpoint. Modules, which contain VBA code are
harder to get going in but are much more flexible and can do a lot
more than macros.

Macros don't have error handling while modules aka VBA code do.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 

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

Similar Threads

Change focus in a form 3
Dates in Access 2
Display Database Window 4
modifiying macros 3
Multi-User DB 4
Problems with a KBV SE Deluxe 1
ECHO OFF applying to MULTIPLE Macros or MODULES! 1
Module to run a macro 2

Back
Top