Access Macros - Then and Now

3 4

In the earliest versions of Microsoft Access (before Access 2.0), there was no code behind forms. All code had to be written as user-defined functions in standard modules and called from event procedures, usually from the OnPush event of command buttons. (The OnPush event was replaced by the OnClick event in later versions of Access.) But users who didn’t want to tackle Access Basic (the dialect of Microsoft Visual Basic used in Access versions earlier than Access 95) had another way to automate Access applications: They could write macros by using the Macro Designer interface and selecting actions from drop-down lists. For beginning to intermediate Access users who weren’t yet ready to write code, macros were a useful tool, enabling them to create fairly complex applications without programming.

In Access 2002 (and even in earlier Access versions), however, macros are somewhat of an anachronism. Although Access databases still have macros (with an interface that hasn’t changed since Access 1.0), the macros aren’t as useful as they once were (with a few exceptions, noted below), for the following reasons:

  • In earlier versions of Access, there were some things you could do with macros but not with code (Access Basic or Visual Basic for Applications [VBA]). For example, you could create menus and toolbars only by using macros. Now, however, you can automate every aspect of an Access database with VBA code, and you can do things in VBA code that you can’t do with macros. (See "Replacing Macros with VBA Code," for details.) For example, you can create menus and toolbars using the CommandBars collection, as described in Chapter 13, "Customizing Access Toolbars and Menus (Command Bars)."
  • Code behind forms (and reports) has made it much easier to run code from form and control events. See Chapter 20, "Customizing Your Database Using VBA Code," for more details on writing event procedures.

Access Macros Compared to Macros in Other Office Applications

Access users who have created Microsoft Word or Microsoft Excel macros might be surprised to find that, unlike macros in all other Office applications, Access macros are not automatically saved as VBA code, and therefore can’t be used as "training" for users who want to move on to writing code. Additionally, Access has no macro recorder (unlike Word and Excel).

If you’re trying to write a Word VBA procedure and you don’t know the syntax for moving to the end of a Word document, for example, all you have to do is turn on the macro recorder, press the Ctrl+End hot key, stop the recorder, and then open the Visual Basic Editor (VBE) window and examine the macro you just created, as shown in the following code. You can then cut and paste the line of code from the new macro to your procedure.

 Sub Macro1() ' ' Macro1 Macro ' Macro recorded 2/23/2001 by Helen Feddema\ '     Selection.EndKey Unit:=wdStory End Sub 

Because it has no macro recorder, you can’t perform this kind of cut-and-paste operation in Access. However, this doesn’t mean that Access macros aren’t useful—you can use them for several special tasks, and even do some simple database automation, as long as you’re aware of their limitations.

InsideOut

Although you can’t record Access macros, the macro recording feature of Word or Excel can be useful when you’re writing Access VBA code that uses Automation to work with Word documents or Excel worksheets. You can record a Word or an Excel macro, open the macro in the VBE window, and cut and paste the sequence of recorded actions to your Access VBA code. This technique can save you from spending a lot of time poring through documentation and online Help to find the syntax for a specific Word or Excel action.



Microsoft Access Version 2002 Inside Out
Microsoft Access Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612838
EAN: 2147483647
Year: 2005
Pages: 172
Authors: Helen Feddema

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net