m My elcome to Access 2007 VBA Programming For Dummies. As you already ▼ ▼ know (we hope), Microsoft Access is a huge database management program, offering lots of ways to manage data (information). Common uses of Access include managing mailing lists, memberships, scientific and statistical data, entire small businesses, and just about anything else that involves storing and managing large amounts of information.

As the title implies, this book is about using Visual Basic for Applications (VBA) to enhance the power of Access databases. If you want Access to print words on a check, skip mailing labels that you've already used, or manipulate data behind the scenes, you have to write VBA code.

By the time you finish this book, you should know exactly what VBA is all about and how it fits into Access. You'll discover the meanings of all those obscure terms that programmers throw around — code, variable, array, loop, object — as though they were common knowledge. You'll be able to write and use your own, custom code, just like advanced programmers do.

This book covers VBA in Access 2007. Although many changes and improvements to Access have occurred in all the versions that Microsoft has released, the VBA programming language has hardly changed a bit over the years. Although Access 2007 looks completely different from previous versions, the underlying objects are virtually unchanged. The code that you see in this book should also work in Access 2000, 2002, and 2003. The vast majority of the code in this book also works just fine even in last century's versions, such as Access 97.

About This Book

We wish we could say that this book is exactly like a coffee-table book, where you could just pick it up, flip to any page, and have everything make perfect sense to you. Well, we could say that, but we'd be lying if we did. It's not because we want to break from the coffee-table book idea. It's really more because some stuff in life doesn't make much sense until after you already know something else.

Here, it isn't really possible to make much sense of VBA code until you understand what VBA code is and why it exists. And, we are talking about Microsoft Access VBA here. To make sense of much of anything in this book, you have to already be familiar with Microsoft Access tables, queries, forms, and reports. We just don't have enough room in this book to explain all that stuff from scratch and still have enough pages left over to talk about VBA.

On the bright side, we did everything we could to make it easy to find what you need to know, when you need to know it. You certainly don't have to read this book from cover to cover to make sense of things. After you find the topic you're looking for, you should be able to read through the section and be done with it quickly. Often, you can skip reading sections altogether and get all you need to know from looking at the figures.

Conventions Used in This Book

While we're on the topic of using this book without boring yourself to death by attempting to read it, we also stuck with some conventions for displaying text in these pages. For example, any VBA programming code appears in a monospace font with a gray background, like this:

'VBA code to say

Hello World on the screen.

Sub Hello()

MsgBox "Hello


End Sub

When we have just a little chunk of code to show in text, like this — Dim Wit As Date — you can see what is and what isn't VBA code.

The O symbol that you see in text separates individual menu options (commands) that you choose in sequence. For example, rather than say "Choose New from the File menu" or "Click File on the menu bar and then click New on the drop-down menu," we just say

Choose FileONew from the menu bar.

When you see something in bold, we want you to enter (type) it.

What You're Not to Read

Not many people in the world would put reading a computer book into the Read for Fun category. We think that reading a computer book is more likely to fall into the Read for Work or Don't Read category. To minimize the time you have to spend away from the fun stuff, we put some information in sidebars and beside Technical Stuff icons. That information is definitely optional reading that you're welcome to ignore.

Foolish Assumptions

To stay focused on VBA in this book, we need to assume that you're already familiar with Access and that you're comfortable creating tables, forms, reports, and queries. However, we don't assume that you're a true Microsoft Access expert. Let's face it: Access isn't exactly an easy program for most people to tackle.

Another assumption we make is that you have already created an Access database with at least some tables and forms in it. In fact, writing VBA code is usually the last step in creating a custom Access database.

Finally, we don't assume that you're already an accomplished programmer who is just picking up a new programming language. Rather, we assume that you've never written any programming code in your life — and maybe you aren't even all that sure what programming code means or how it relates to Microsoft Access.

How This Book Is Organized

All books contain a lot of information. That's what makes them books. To break down topics into smaller, more manageable chunks, we split this book into six main parts.

Part I: Introducing VBA Programming

This part has all the information you need to get started. If you've already been using VBA for a few months or years, you can skim this part. If you don't know a VBA procedure from a PTO meeting, you might want to take a closer look at Part I before venturing forth to other parts.

Part II: VBA Tools and Techniques

Here you discover how to write VBA code to make Access do things for you. For example, you'll see how you can make Access open forms, respond to button clicks, change the appearance of objects, and more.

Part III: VBA, Recordsets, and SQL

Here you get friendly with tools and techniques for managing your Access tables by using VBA with SQL (Structured Query Language) and recordsets. All those buzzwords make this process sound more technical than it really is. But as you'll see, if you've done anything at all with queries, you've already been working with SQL recordsets. The idea is the same. We just use fancier terminology in the VBA world.

Part IV: Applying VBA in the Real World

In this part, you get into some more advanced programming tricks, mostly by using techniques presented in earlier parts in new and creative ways. You'll also see how to use the VBA debugging techniques, which can be real lifesavers when things go wrong and you just can't figure out why the code you wrote isn't doing what you intended.

Part V: Reaching Out with VBA

VBA isn't a programming language solely for Microsoft Access. You can also use VBA to customize all the Microsoft Office application programs, including Word, Excel, and Outlook. Furthermore, VBA can import data from, and export data to, a variety of formats that extend its reach even beyond Microsoft Access. Part V shows you how that's all done.

Part VI: The Part of Tens

What For Dummies book would be complete without a Part of Tens? Ten is such a nice number to work with, given our ten fingers and all. Chapter 15 covers the main strategies that you can adopt to avoid going crazy trying to get VBA to do your bidding. Chapter 16 goes over the top ten nerdy programming tricks you're most likely to want to do almost from your first day of using VBA.

Icons Used in This Book

As you flip through this book, you'll notice little icons sprinkled throughout its pages. These icons, as described here, point out little chunks of text that deserve either a little extra attention or very little attention:

Tips point out handy tricks or techniques that can make things easier for you when you're working with VBA.

These icons point out techniques that, if you do things wrong, might create problems. If you pay attention to the Warnings we give, you can avoid making common blunders.

These icons point out tools and techniques that you'll use often as you work with VBA. Keep them in mind.

These icons point out text that describes how or why a thing works the way it does from a technical standpoint. If you just want to get a thing to work and don't care about how or why it works, you can always skip these.

Web Site for This Book

If you can find a way to copy and paste — rather than type — VBA code into your database, go for it. Much of the sample VBA code shown in this book is the kind of thing you can just drop into an Access database and start using. There's no need to retype the whole thing. Anyway, we post all the useful code at this Web site: 007vbaprog

When you get to the site, you'll see where to find the code and how to copy and paste it into your own database, and find a link where you can send us your questions.

Where to Go from Here

Now that you know what this book is about and how it's organized, the next question is "Where do I start?" Your best bet, if you're an absolute VBA beginner, is at Chapter 1. Try to slog through the first three (short) chapters to get your bearings.

Experienced VBA users can probably start anywhere that looks interesting. If you get in over your head at some point, watch for cross-references to earlier chapters where you can quickly fill in the knowledge gap that's causing the confusion.

Was this article helpful?

0 0

Post a comment