Presentation is loading. Please wait.

Presentation is loading. Please wait.

WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.

Similar presentations


Presentation on theme: "WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS."— Presentation transcript:

1 WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS

2 1. Introduction A macro helps you perform routine tasks by automating them Record a single macro that does the entire task all at once instead of manually performing a series of time-consuming, repetitive actions. A macro is a set of one or more actions that perform a particular operation

3 2. Creating and Running a Macro Simple macros that automate a single task, such as opening a form or report, are simple to create Complicated macros with several steps or procedures require planing. Before creating a complicated macro, identify what the macro will do and the individual actions that are required to complete this operation.

4 2. Creating and Running a Macro In the database window, click the macros icon in the objects bar and click the new button. In action column, select the action you want the macro to perform. Specify any required arguments for the action in the action arguments area. Cick the save button on the toolbar

5 2. Creating and Running a Macro

6 Click the macros icon in the objects bar and double-click the macro you want to run or click run button

7 3. Editing a Macro Macros can contain many actions to automate even the most complicated tasks Each action appears in its own row and is executed in the order in which it appears in the Macro window, from top to bottom. To modify a macro: ◦ In the database window, click the macros icon in the objects bar, select the macro you want to edit, and click the design button.

8 4. Working with Macro Groups A macro group stores several related macros together in a single macro object To create a macro group, give each macro in the macro group its own unique name by entering the macro names in the Macro Name column (by clicking the Macro Names button on the toolbar). When combine two or more macros within the same macro group, must run them separately, by referring to the macro group name, followed by the macro name

9 4. Working with Macro Groups

10 To run a macro in a macro group: Select tools  macro  run macro from the menu. Click the macro name list arrow, select the macro you want to run, and click ok

11 5. Assigning a Macro to an Event To assign a macro to a control on a form or report: Open the form or report in design view. Click the control to which you want to assign the macro and click the properties button on the toolbar.

12 5. Assigning a Macro to an Event Click the event tab and click in the box for the type of event you want to assign to the macro. Select the macro you want to assign to the event. Close the properties dialog box and save the form or report.

13 5. Assigning a Macro to an Event EventDescription Before Update Macro or function that runs when data in a field or record is changed but before the changes are actually saved to the database. Often used to validate data. After Update Macro or function that runs when data in a field or record is changed and is saved to the database.

14 5. Assigning a Macro to an Event On Change Macro or function that runs when the contents of a text box or combo box changes or when you move from one page to another page in a tab control. On Enter Macro or function that runs when a control first gets the focus. The Enter event occurs before the focus moves to a particular control. You can use an Enter macro or event procedure to display instructions when a form or report first opens. On Exit Macro or function that runs when a control loses focus (is deselected) on the same form.

15 5. Assigning a Macro to an Event On Got Focus Macro or function that runs when a control gets the focus (is selected). On Lost Focus Macro or function that runs when a control loses the focus (is deselected). On Click Macro or function that runs when a control is clicked. On Dbl Click Macro or function that runs when a control is double-clicked.

16 5. Assigning a Macro to an Event On Mouse Down Macro or function that runs when the user presses the mouse button. On Mouse Move Macro or function that runs when the user moves the mouse over a control. On Mouse Up Macro or function that runs when the user releases the mouse button. On Key Down Macro or function that runs when the user presses a key on the keyboard. On Key Up Macro or function that runs when the user releases a key on the keyboard. On Key Press Macro or function that runs when the user presses an ANSI key on the keyboard.

17 6. Creating Conditional Expressions The macro condition states this effectively: If this condition is true, run this action. If it is not true, go to the next action, if any. Normally, a condition applies only to the action on the same row in the macro sheet. If the condition isn’t met, the next action is executed. To continue the condition to the next action, enter an ellipsis (…) in the Condition column of the next row. You can apply the condition to several sequential actions

18 6. Creating Conditional Expressions

19 To add the Condition column to the macro sheet, click the Conditions button or choose View | Conditions. Type the logical expression for the condition in the row with the action you want to carry out if the condition is True. If you want to use the Expression Builder to help with the expression, right-click in the Condition column and choose Build from the shortcut menu.

20 7. Some Common Uses for Macros Displaying a Message Box MsgBox display warnings, alerts, and other information MessageEnter the text of the message you want displayed when the Beepsound a beep signal when the message TypeSets the type of message box, each of which displays a TitleText that displays in the message box title bar

21 7. Some Common Uses for Macros Setting Values and Properties ◦ Set the value of a control based on the value of another control in the same or a different form or report Many of the properties of forms, reports, and controls can be set by running a macro. For example, you can hide a control from view on the form or disable it so the user can’t enter data in it.

22 7. Some Common Uses for Macros The MsgBox function is similar to the MsgBox action with the exception that the function returns one of seven different values, depending on which button the user clicks in the message box The MsgBox function displays a dialog box containing the message and waits for the user to click a button indicating the user’s choice The MsgBox function has three main arguments; only the first is required

23 7. Some Common Uses for Macros ◦ Prompt is a string expression displayed in the dialog box. ◦ Button is a number equal to the sum of three values that specify the visual characteristics of the message box ◦ Title is a string expression displayed in the dialog box title bar

24 7. Some Common Uses for Macros You can also specify which of the buttons is the defaultYou can also specify which of the buttons is the default ValueButtons To Display: 0Display only the OK button. 1Display the OK and Cancel buttons. 2Display the Abort, Retry, and Ignore buttons. 3Display the Yes, No, and Cancel buttons. 4Display the Yes and No buttons. 5Display the Retry and Cancel buttons.

25 7. Some Common Uses for Macros Icons To Display: 0Display no icon. 16Display the Critical Message icon. 32Display the Warning Query icon. 48Display the Warning Message icon. 64Display the Information Message icon.

26 7. Some Common Uses for Macros When you use the MsgBox function in a macro condition, you can compare the returned value to a specific number and carry out the action if the comparison is True ButtonReturned Value OK1 Cancel2 Abort3 Retry4 Ignore5 Yes6 No7

27 8.Creating an AutoExec Macro You can create a special macro that runs when you first open a database. The AutoExec macro can carry out such actions as open a form for data entry, display a message box. All you need to do is create the macro with the actions you want carried out at startup and save it with the name AutoExec. Adatabase can have only one macro named AutoExec

28 9. Macro Action Reference (tự tham khảo)


Download ppt "WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS."

Similar presentations


Ads by Google