Access 2013 All-in-One For Dummies
Book image
Explore Book Buy On Amazon

When you’re automating an Access 2013 database application by using Visual Basic for Applications (VBA), you can get lost with a blank page to begin writing code. Where do you start? Here are a few simple guidelines to follow that will have you writing VBA code like a pro:

  1. Get help.

    Press F1 at any time to start Microsoft Access help, where you can see examples of VBA code.

  2. Use the Object Browser.

    The Object Browser lets you explore the properties and methods of the objects in VBA. In the Visual Basic Editor, choose View, then Object Browser or simply press F2.

  3. Get more help.

    Sure, the built-in help tools within VBA are wonderful, but you can also use your favorite browser to search the Internet for help on writing VBA code. You can even find examples that you can steal — or borrow — for your own project.

  4. Handle your errors.

    Even the most perfect programmer can’t stop errors from occurring, but he or she can stop them from bringing a program to a grinding halt. Use VBA’s built-in error handling with the On Error Goto and Resume statements to trap errors and change the program flow so that your applications don’t frustrate the people who use them.

  5. Use functions and sub procedures.

    Employ functions and sub procedures to handle tasks that will be performed by different areas of your program. As a general rule, if you find yourself copying and pasting code from one area of a program to another, you may want to put that code in its own procedure.

  6. Convert macros to VBA code.

    The macro designer in Access 2013 lets you choose among lists of predefined tasks to automate your application. Build a macro that does what you want and then convert that macro to VBA code so you can see how it would look if you’d typed it from scratch.

About This Article

This article is from the book:

About the book authors:

Alison Barrows is the author or coauthor of several books about Access, Windows, and the Internet. Joseph Stockman is an 18-year software designer who has authored or coauthored five Access programming books. Allen Taylor is a 30-year veteran of the computer industry and the author of over 20 books.

This article can be found in the category: