Access VBA Macro Programming

(Joao Candeias) #1

Chapter 3 Modules, Functions, and Subroutines


Chapter 3 Modules, Functions, and Subroutines


M


odules are containers where you write your code. Functions and subroutines
are the two different ways of creating a piece of working code.

Modules


Modulesare code sheets that are specific to your application. They are not fired off directly
by events in the database, but have to be called directly. They are a means of creating procedures
in a general manner, rather than specifically running in an object like a form or a report. You
can call them in a number of ways:


 Use a custom ribbon command or a custom toolbar command. See Chapter 11 for more
on customizing the ribbon.
 Insert a VBA control from the Control toolbox into the form or report directly and
attach your code to this. For example, you might enter code for a user’s actions on a
command button or a combo box.
 Run the code from a form. In Chapter 9, you will learn how to define your own forms,
which the user can employ to make selections and take options. When the user clicks
the OK button on the form, your macro runs and picks up the user preferences.

27

Free download pdf