Home

Using Visual Basic for Applications Efficiently in Access 2013

|
Updated:  
2016-03-26 15:40:35
|
Access Forms and Reports For Dummies
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 author:

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.

Joe Stockman is an independent consultant, software designer, and author who has been using Microsoft Access since its initial release. He’s also developed courseware and taught classes in Access and VBA. Joe developed his first application in Access, and then migrated into Visual Basic and VB.NET, where he specializes in creating applications for the Windows Mobile platform. He worked for several software companies before forming his consulting business in 2002, where he deals with all types of clients including healthcare, financial, government, manufacturing, and small business. His ability to turn his customers’ wishes into working applications keeps them satisfied. Joe’s also writing the fundamentals column for the Advisor Guide to Microsoft Access magazine.

Allen G. Taylor is a 30-year veteran of the computer industry and the author of over 40 books, including SQL For Dummies and Crystal Reports For Dummies. He lectures nationally on databases, innovation, and entrepreneurship. He also teaches database development internationally through a leading online education provider.