, Access 2002 Bible 

[ Pobierz całość w formacie PDF ]
.For exam-ple, you may want to have Access open two forms, displaying an hourglass whilethey are opening.Finally, you can have the computer beep for the user after com-pleting the macro.To accomplish these multiple actions, follow these steps:1.Open a new Macro Design window.2.Click the first empty cell in the Action column.3.Select the Hourglass action from the drop-down list or type it.4.Click in the Comment cell alongside the Hourglass action.5.Type Display the hourglass while the macro is running.6.Click the next empty cell in the Action column.7.Select the OpenForm action from the drop-down list or type the name of theaction.8.Click the argument cell Form Name.9.Select the Add a Customer and Pets form.10.Click the Comment cell alongside the OpenForm action.11.Type Open the Add a Customer and Pets form.12.Click the next empty cell in the Action column.13.Select the OpenForm action from the drop-down list or type the action.14.Click the argument cell Form Name.15.Select the Adding Visit Details form.16.Click the Comment cell alongside the OpenForm action.17.Type Open the Adding Visit Details form.18.Click the next empty cell in the Action column.19.Select the Beep action from the drop-down list or type the action.Your macro design should now look similar to Figure 28-5.This macro opens bothforms as it displays the hourglass.After both forms are open, the macro beeps tosignal that it is finished. 3596-X ch28.F 5/30/01 11:45 AM Page 902Part V &' Access Application Tools902Figure 28-5: Adding multiple actions to a single macro.Thisone opens two forms and beeps when done.TipWhen you re adding more than one action, you can specify each action, one afterthe other, with several rows of spaces between them.These blank rows can con-tain additional lines of comments for each macro action.At this point you can see what the macro does by saving and running it.To do thisquickly while still in the Macro Design screen, following these steps:1.Click on the Run button (the red exclamation point on the toolbar) or selectRun ª' Run from the menu.Access informs you that you must save the macro before running it.2.Select the Yes button to save your macro.Access opens the Save As dialog box.3.Type OpenTwoFormsin the text box and either press the Enter key or click theOK button.Access saves the form and runs the macro  showing the hourglass and open-ing the two forms, finally beeping.4.Under the forms the macro is still open.Access opened the forms so quickly that you probably did not see the Hourglassdisplayed, although it was.Using this method of running a macro you can test tosee if it works correctly.However, this is not the normal way that a macro would beexecuted.Normally you will attach the completed macro to an event property of aform or report.Attaching the macro to an event property is covered later in thischapter.NoteYou should close both forms and leave the macro open for the next section.Rearranging macro actionsWhen you work with multiple actions in a macro, you may change your mind aboutthe order of the actions.For example, you may decide that the macro created inFigure 28-5 should have the Beep action come first in the macro.To move theaction, follow these steps: 3596-X ch28.F 5/30/01 11:45 AM Page 903Chapter 28 &' Working with Macros and Events9031.Select the Beep action by clicking the row selector to the left of the actionname.2.Click the highlighted row again and drag it to the top row.Deleting macro actionsIf you no longer need an action in a macro, you can delete the action.In the exam-ple of the macro shown in Figure 28-5, to delete the action to open the form AddingVisit Details, follow these steps:1.Select the action OpenForm for Adding Visit Details by clicking the row selec-tor to the left of the action s name.2.Press Delete or select Edit ª' Delete Row from the menu.TipYou can also delete a row by using the right-click shortcut menu: Select the row todelete, press the right mouse button, and select Delete Row.You have already saved two macros above using two different methods.It is impor-tant to stress again that before you can run a macro, it must be saved.After yousave a macro, it becomes another database object that can be opened and run fromthe Database window.In general to save a macro, follow these steps:1.Select File ª' Save from the Macro Design menu or click the Save button on thetoolbar.2.If the macro has not been saved, you must enter a name in the Save As dialogbox.Press Enter or click OK when you re through.TipThe fastest way to save a macro is to press F12 or Alt+F2 and give the macro aname.Another way is to double-click the Macro window s Control menu (top-leftcorner) and select close the window, or click on the Exit button, and answer theappropriate dialog box questions.You can also save a macro by running it and youwill be prompted to save it before it is executed.Editing existing macrosAfter a macro is created, it can be edited by following these steps:1.In the Database window, select the Macros object button.2.Highlight the macro you want to edit.3.Click the Design button in the Database window.With the macro in design mode you can now add additional actions or modify exist-ing actions.Once you edit the macro you will need to save it again. 3596-X ch28.F 5/30/01 11:45 AM Page 904Part V &' Access Application Tools904Copying entire macrosTo copy a macro, follow these steps:1.Click the Macros object button in the Database window.2.Select the macro to copy.3.Press Ctrl+C or select Edit ª' Copy to copy the macro to the Clipboard.4.Press Ctrl+V or select Edit ª' Paste to paste the macro from the Clipboard.5.In the Paste As dialog box, type the macro s new name.Renaming macrosSometimes you need to rename a macro because you changed the event property inthe form or report property.To rename a macro, follow these steps:1.Select the Database window by pressing F11 or Alt+F1.2.Click the Macros object button to display all the macro names.3.Highlight the macro name to change.4.Choose Edit ª' Rename from the Database menu or right-click and chooseRename from the shortcut menu.5.Enter the new name.Running MacrosAfter a macro is created, it can be run from any of these locations within Access:&' A Macro window&' A Database window&' Other object windows&' Events such as a form opening or closing&' Another macroRunning a macro from the Macro windowA macro can run directly from the Macro Design window by clicking the toolbar sRun button (the exclamation mark) or by choosing Run from the Design menu. 3596-X ch28.F 5/30/01 11:45 AM Page 905Chapter 28 &' Working with Macros and Events905Running a macro from the Database windowA macro can be run from the Database window by following these steps:1.Click the Macros object button in the Database window.2.Select the macro to run.3.Either double-click the macro or choose the Run button.Running a macro from any window in the databaseTo run a macro from any window in the database, follow these steps:1.Select Tools ª' Macro from the menu.2 [ Pobierz caÅ‚ość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • anikol.xlx.pl