Advantages to Using VBA over Macros

While macros are perfectly acceptable and even recommended in certain situations, there are some key advantages to using VBA. The following is a list of some of the advantages you'll enjoy by using VBA instead of a macro.

□ Speed: A one-action macro will probably execute faster than the equivalent VBA code. However, running a complex macro with 10 or 12 actions usually takes significantly longer than the equivalent code. VBA code within Access is fast. If you're designing an end-user application, you definitely need to be concerned with speed. If your users see the hourglass for even more than 5 or 6 seconds, their perception will be that your application is slow.

□ Functionality: With 70 macro actions, how could you ever miss functionality? We're being facetious, of course—if all Access programming were limited to 70 actions, there wouldn't be many applications written in Access. How would you play a sound other than the default "beep" or open an HTML file in response to a button click? VBA provides so much more functionality than Access macros do. For example, VBA gives you the capability to interact with other applications. Using VBA, you can open Word or Excel files, send e-mail from Outlook, open an Internet Explorer browser and navigate to a particular Web site, or open almost any file stored on your computer or a network drive. External application access isn't limited to Microsoft products either. You can add a reference to any number of applications through the References dialog box in Access VBA. Once you've added a reference, you can control other applications such as Adobe Acrobat, VMWare, or Yahoo Messenger. You can also take advantage of many Web services, such as MapPoint and CarPoint.

□ Control: With VBA, you can exercise almost complete control over your code. Instead of having to let the chosen macro actions perform the work, you can control each step of the process in VBA. Some tasks—such as dynamically creating an ADO connection based on user input— simply cannot be accomplished using macros. Some tasks are possible, but considerably more difficult. Asking for a variety of variables to input into an equation, for instance, can be easily accomplished using VBA, but is rather difficult using a macro (macros would require a TempVar or hidden form to store the data). Macros cannot easily run a different set of actions for each user of your application. VBA can accomplish this task with ease.

□ Interaction with other applications: When using VBA in Access you're not limited to merely programming Microsoft Access. You can add references to other object libraries such as Word, Excel, Outlook, and even non-Microsoft programs including accounting packages, drafting programs, and even graphics programs.

Was this article helpful?

0 0

Post a comment