Converting Your Macros to Visual Basic


As you’ll learn in the rest of this book, Visual Basic, rather than macros, is what you should use to automate any serious applications. If you’ve spent some time getting familiar with programming in Access in macros but would now like to move to Visual Basic, you’re in luck! Access provides a handy tool to convert the actions in macros called from events on your forms and reports to the equivalent Visual Basic statements.

To see how this works, open the WeddingList form in Design view. On the Database Tools tab, in the Macro group, click the Convert Form’s Macros To Visual Basic button, as shown in Figure 18–41.

image from book
Figure 18–41: Access includes a command to convert a form’s macros to Visual Basic.

In the next dialog box, the Convert tool offers you the option to insert error-handling code and to copy the comments from your macros into the new code. You should leave both check boxes selected and then click Convert to change your macros to Visual Basic. After the tool is finished, you should see all macro references in event properties changed to [Event Procedure]. Click the On Current event property for the WeddingList form, and then click the Build button () to the right of the property. You’ll see the converted code displayed, as shown in Figure 18–42.

image from book
Figure 18–42: Access converted the macro from the Current event of the WeddingList form to Visual Basic.

Note 

Converting your macros to Visual Basic does not delete any of your original macros. However, Access removes any embedded macros assigned to form and control properties and converts them to Visual Basic. Also, the tool doesn’t convert any macros referenced by a RunMacro command-you’ll have to do that yourself.

In Chapter 20, we’ll introduce you to some enhancements we made to the Wedding List sample database after we converted all the macros to Visual Basic using this wizard. You can find this version of the database saved as WeddingList.accdb on the companion CD.

image from book Article 6, on the companion CD, summarizes all the actions you can include in macros You’ll find it useful to browse through that article to become familiar with the available actions and events before going on to the next two chapters, where you’ll learn about Visual Basic and where you’ll see how the other sample applications are automated using Visual Basic.




Microsoft Office Access 2007 Inside Out
MicrosoftВ® Office Access(TM) 2007 Inside Out (Microsoft Office Access Inside Out)
ISBN: 0735623252
EAN: 2147483647
Year: 2007
Pages: 234

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