Continued from Create Menus with Macros. - Access 2003
Continued from last week’s article: [Create Menus with Macros] – please review it before proceeding.
In the previous article, we learned how to create a simple Shortcut Menu for Forms using Macros. This week, we will take this concept further and demonstrate how to create a Toolbar Button and a Menu Bar item using Macro-based menus.
New Macro: macProcess.
But, before all that, let us make some modifications to our earlier shortcut menu to add a menu group item with a few options.
Open a new macro in the design view.
Select MsgBox from the drop-down list in the Action Column.
Type Proceed with Report Data Processing? In the Message control under the Action Argument list.
Select Critical from the drop-down list in the Type control.
Type Report Processing in the Title control.
Note: The purpose of this macro is to hold a series of actions, such as running action queries (Make-Table, Append, Update, Delete), executing other macros, or calling VBA routines to prepare data for reports. In this example, we are using a message box to display a sample message. In practice, you should design your menus with actions tailored to the specific requirements of your application.
Save the Macro with the name: macProcess and close it.
The macSubMenu Macro.
Click on New to open another new macro in Design View.
If the Macro Name Column is not visible, then select Macro Name from the View Menu.
Type &Form in the Macro Name column of the first row and select OpenForm from the drop-down list under the Action Column.
Select an existing Form in the Form Name control using the drop-down control.
Type Process &Data in the Macro Name column in the second row and select the RunMacro in the Action Column.
Type macProcess (or select it from the drop-down list) to insert the process macro that we have created in step 6.
Type &Report in the Macro Name column in the third row and select OpenReport in the Action column.
Select an existing Report from your application in the Report Name control.
Select Print Preview in the View control.
Save the macro with the name macSubMenu and close it.
Modify Macro: mcrShortCut
Open the macro mcrShortCut that we created last week.
Type MenuGroup in the next row (as shown in the image given below) and select the AddMenu option from the drop-down list under the Action column.
Type Form/Report in the Menu Name control below the Action Arguments.
Type macSubMenu (or select from the drop-down list) in the Menu Macro Name control.
Save and close the macro mcrShortCut.
If you recall the Form to which you attached the shortcut menu in last week’s exercise, open that form in Normal View and right-click anywhere on it to display the Form/Report submenu we added earlier. If you don’t remember, simply open any of your existing forms in Design View to continue.
Display the Property Sheet (View -> Properties or press ALT+Enter).
Click on the Other Tab.
Set the Shortcut Menu Property value to Yes.
Set the Shortcut Menu Bar Property value to macMenu (you can select the macro from the drop-down list also).
Save and close the Form.
The Shortcut Menu Trial Run.
Open the Form in Normal View.
Right-click on a field to display the Shortcut Menu. The new Group Menu that we have added will appear at the end of the Menu with the description Form/Report.
Place the mouse over the Form/Report menu group to display its Sub-Menu items.
The menu definition now remains in Macros, and we are directly using it on Forms. But, we can convert the Menu Macro into a regular:
- Menu Bar (like File, Edit, etc.) OR
- Toolbar OR
- Shortcut Menu.
If you would like to convert this macro menu into a Menu Bar, then we must make a small change in the macMenu macro.
Converting Macro into Menu Bar.
Open macMenu in design view.
Type myMenu in the Menu Name control under Action Arguments.
Save and close the macro.
Click on the macMenu macro to select it.
Highlight the Macro in the Tools Menu.
Click on Create Menu from Macro Option.
A Menu Bar will appear on top with the label myMenu.
Click on the myMenu option to display the menu options for which we have created macros.
Note: You should not attempt to convert the same macMenu to a Toolbar Menu; a name conflict may take place.
Quick Toolbar Button.
Tip: To create a quick Toolbar Button with the same set of macros, do the following:
Make a copy of the macros: macMenu, mcrShortCut, and macSubMenu, and name them as mac_Menu, mcr_ShortCut, and mac_SubMenu.
Open the mcr_ShortCut macro in design view.
Click on the last line and change the Menu Macro Name control value to mac_SubMenu, save, and close the Macro.
Open the Mac_Menu macro in the design view.
Change the Menu Name control value to myToolbar.
Change the Menu Macro Name control value to mcr_ShortCut, save, and close the mac_Menu Macro.
Click on the Mac_Menu Macro to select it.
Highlight the Macro in the Tools Menu to display its Options.
Click on Create Toolbar from the Macro option to convert the macro into a Toolbar; the myToolbar button will appear near the existing Toolbar with the label myToolbar.
You may click on it to display the Menu.
No comments:
Post a Comment
Comments subject to moderation before publishing.