Access VBA Macro Programming

(Joao Candeias) #1

CHAPTER


1


The Basics


T


his chapter is intended to take you through the basic steps of using the Visual Basic
Editor window and writing a simple piece of VBA code. It will show you how to use
the Visual Basic Editor (VBE), and the Project Explorer and code windows. You will
learn how to write a simple macro to display a “Hello World” message box.


Macros and VBA Modules in Access


You may have noticed that in Access you can create both macros and modules containing
VBA code. What is the difference between these? They are both a means of creating
automation procedures, but macros are more limited than modules and do not use VBA.
If you click Create on the menu bar and then click the Macro icon in the Macros and Code
section of the ribbon, you will see the macro editor window shown in Figure 1-1.
If you click the Add New Action drop-down, a drop-down of various macro commands
such as CloseWindow or DeleteRecord will appear. If you click one of these options, you can
enter in parameters such as the name of the form to be opened or add a filter.
Basically, it is a simplistic means of building a macro, but it is nowhere near as rich and
flexible as a VBA module. Everything offered in the Macro Editor can also be used in VBA
modules (albeit in a different format) and the modules offer the flexibility of a real
programming language. Note that many macro commands can be used directly within VBA
code. Since this book concentrates on VBA modules, macros will not be discussed further.


3

Free download pdf