CHAPTER 23Using Access Data Macros

For a long time, macros were considered the poor cousins of VBA statements. Although in many ways VBA and macros were equivalent in their capabilities, macros have always been considered inferior to VBA for handling an application's logic.

The problems with traditional Access macros were considerable:

  • Macros existed as separate database objects, so keeping track of the macro's effect on a particular form was often difficult. Because there was no direct connection between a form (or a report, for that matter) and a macro, it was easy to break the macro by deleting or renaming it. VBA code encapsulated within the form's code module never had this problem.
  • There was no way to trap or handle errors in macros. In versions of Access prior to 2007, macros would simply stop running and display an error dialog box if something unexpected happened. These interruptions were not welcomed by users, particularly because there was, most often, nothing a user could do to correct the problem or prevent it from happening again. VBA code has always featured strong error handling and could often provide a default value or instruct the user what to do in the event of a problem.
  • Macros were unable to work with code. There was no way for a macro to loop through a recordset—for example, to sum field values or detect out‐of‐range data. VBA code is well suited ...

Get Access 2019 Bible 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.