Chapter 16. Automating Tasks with Visual Basic

Macros are plenty of fun, but they can only do so much. If you can’t find a readymade macro action that does the job you want, you can’t use a macro. No such limit applies in the world of Visual Basic code, where you can do just about anything (if you spend enough late-night hours at the computer keyboard).

Here are some examples of tasks you can accomplish with code, but not with macros:

  • Modify a whole batch of records at once.

  • Deal intelligently with errors so Access doesn’t pop up a cryptic message.

  • Perform complex calculations. You can calculate an order confirmation code using a secret algorithm, or transform a line of text into Pig Latin.

  • Interact with other programs on your computer. For example, you can copy some data out of a table and into a Word document.

  • Write even more sophisticated validation routines that lock out bad data.

The goal of this chapter (and the next) isn’t to make you a full-time code jockey. If that’s your ambition, you can continue on to read entire books about programming Access. Instead, this chapter aims to teach you just enough to get the lowhanging fruit of Access programming. In other words, you’ll pick up enough VB smarts to use the popular and practical code tricks discussed in the next chapter. You’ll also build a great foundation for future exploration.

Note

The version of Visual Basic that Access and other Office applications use is called VBA, which stands for Visual Basic for Applications ...

Get Access 2007: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.