Access VBA Macro Programming

(Joao Candeias) #1
Since VBA is shared by all Office applications, a great deal of the information contained
in this book will help with other Office applications such as Word or Excel and also with
Visual Basic itself. VBA is more powerful than the previous text macro language and enables
you to extend Access in any way you choose. It lets you write code to do things that are not
within the Access menu structure. It even provides a means to access and manipulate other
Microsoft Office applications under software control. For example, by using the Outlook
object model, you can copy address lists onto your database merely by executing VBA code.
This will happen even if Outlook is not running since Outlook only needs to be installed for
the object model to work.
By the same token, you can also manipulate the Access object model from another Microsoft
application. For example, you can produce an Excel spreadsheet file from Microsoft Access
without Excel ever appearing onscreen or being loaded. Access users know that it is very easy to
write a macro to export a table into Excel, but what if you desire information from several tables
and you want presentation formatting on the numbers, as well as audit trails on the figures
explaining how they were calculated? VBA lets you do this.
VBA is an object-oriented language that requires a totally different viewpoint from the old
text-based macro programming. All objects can have events, methods, and properties, and
these can be manipulated to assist your programs. The objects are arranged in a hierarchy.
This concept is explained in more detail in Chapter 12.
Whether you are totally new to macro programming in Access or simply want to update
your skills, this book will show you how to use the Access object models along with VBA to
learn how to program macros effectively.

The Objectives of this Book
The first objective of this book is to show you how VBA works in Access and the basics of
object-oriented programming. The intricacies of the VBA programming language are explained,
and specific keywords and functions are discussed. It then takes you through a number of
worked examples, detailing how to set up subroutines and functions. Full source code is
shown for all examples.
The book not only shows you how to do things that are on the Access menu but also
describes how to do several things outside of the Access menu structure and make them all
look absolutely mind-blowing in a database. People seeing them for the first time and not
knowing they were done through VBA code will either be amazed and congratulate you on
your knowledge, or quietly go away and study the menu structure to see if there is a way of
doing it without using VBA (which, of course, there is not). Examples like this can be found
in Chapter 11, which shows you how to set up your own ribbon menu structures within Access,
and Chapter 35, which explores how to control the population of an Excel spreadsheet from
Access.

xxiv Microsoft Access 2010 VBA Macro Programming

Free download pdf