Download presentation
Presentation is loading. Please wait.
Published byἸωακείμ Τομαραίοι Modified over 6 years ago
1
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Exploring Microsoft Office 2016 Series Editor Mary Anne Poatsy Cameron |Williams Series Created by Dr. Robert T. Grauer
2
Copyright © 2017 Pearson Education, Inc.
Chapter 10 In Chapter 10, you will learn how to create and use macros and SQL to manage data within a database. Using Macros and SQL in Access Advanced Techniques Copyright © 2017 Pearson Education, Inc.
3
Copyright © 2017 Pearson Education, Inc.
Objectives Understand the Purpose of a Macro Create a Stand-Alone Macro Use the Macro Designer to Edit a Macro Attach an Embedded Macro to an Event Identify When to Use a Data Macro The objectives for this chapter are: Understand the Purpose of a Macro Create a Stand-Alone Macro Use the Macro Designer to Edit a Macro Attach an Embedded Macro to an Event Identify When to Use a Data Macro Additional objectives are listed on the next slide. Copyright © 2017 Pearson Education, Inc.
4
Copyright © 2017 Pearson Education, Inc.
Objectives Create an Event-Driven Data Macro Create a Named Data Macro Understand the Fundamentals of SQL Interpret an SQL Select Statement Use an SQL Select Statement as a Record Source The objectives for this chapter are: Create an Event-Driven Data Macro Create a Named Data Macro Understand the Fundamentals of SQL Interpret an SQL Select Statement Use an SQL Select Statement as a Record Source Copyright © 2017 Pearson Education, Inc.
5
Objective 1: Understand the Purpose of a Macro
In this section, the skills include: Understand How a Macro Automates Tasks in a Database Skills: Understand How a Macro Automates Tasks in a Database Copyright © 2017 Pearson Education, Inc.
6
Understand the Purpose of a Macro
Macro—series of actions that can be programmed Two types of macros: Stand-alone—created and used independently of other controls or objects Embedded—executes when an event attached to a control or object occurs Event—occurs when an action takes place A macro is a series of actions that can be programmed to automate tasks. You will learn how to create two types of macros: stand-alone macros and embedded macros. A stand-alone macro is a database object that is created and used independently of other controls or objects. An embedded macro is a macro that executes when an event attached to a control or object occurs. An event occurs when an action takes place, such as a user entering, editing, or deleting data or a user opening, using, or closing a form or a report. Copyright © 2017 Pearson Education, Inc.
7
Understand the Purpose of a Macro
Macros category A stand-alone macro displays as an object in the Navigation Pane. As shown in the slide, Macros is an object category like Tables or queries, and there are three macros in the database. Stand-alone macros Copyright © 2017 Pearson Education, Inc.
8
Objective 2: Create a Stand-Alone Macro
In this section, the skills include: Create a Stand-Alone Macro with the Macro Designer Skills: Create a Stand-Alone Macro with the Macro Designer Copyright © 2017 Pearson Education, Inc.
9
Create a Stand-Alone Macro
MessageBox action Message Title Macro Designer is a tool that makes it easier to create or modify macros, and to add or delete actions from macros. When designing a macro, you add actions that will list the tasks that you want the macro to perform. After adding an action to the macro, you specify the arguments you want for the action. An argument is a variable, constant, or expression that is used to produce the output for an action. There are three ways to add actions to a macro, and we will focus on one of these. To create a stand-alone macro using the Macro Designer, you: Click Macro in the Macros & Code group on the Create tab to display the Macro Designer. Locate an action in the Action Catalog, and double-click it. Specify the arguments you want for the action you added to the macro. Add actions and arguments to the actions to continue to build the macro. Click Save, and type descriptive name for the macro. This slide shows the selection of the MessageBox action, where the message and title have been added. Named macro Copyright © 2017 Pearson Education, Inc.
10
Objective 3: Use the Macro Designer to Edit a Macro
In this section, the skills include: Edit a Stand-Alone Macro with the Macro Designer Skills: Edit a Stand-Alone Macro with the Macro Designer Copyright © 2017 Pearson Education, Inc.
11
Use the Macro Designer to Edit a Macro
OpenForm action Once a stand-alone macro has been created, you might need to modify, add, or delete actions. To edit a stand-alone macro using the Macro Designer, you: Right-click the macro name in the Navigation Pane. Select Design View from the shortcut menu. Modify, add, or delete macro actions, then save and close the macro. This slide shows the MessageBox action has been changed to the OpenForm action. Copyright © 2017 Pearson Education, Inc.
12
Objective 4: Attach an Embedded Macro to an Event
In this section, the skills include: Create an Embedded Macro Using the Command Button Wizard Format a Command Button Create an Embedded Macro with an Event Property Create a Message Box Skills: Create an Embedded Macro Using the Command Button Wizard Format a Command Button Create an Embedded Macro with an Event Property Create a Message Box Copyright © 2017 Pearson Education, Inc.
13
Attach an Embedded Macro to an Event
Button control Select category Select action An embedded macro is attached to an event of a control on a form or report, or to an event of the form or report itself. Remember, an event is an action, and an example of an event is closing a form. To create an embedded macro using the Command Button Wizard, you: Right-click the form or report in the Navigation Pane, and select Design View. Click the Button control in the Controls group on the Design tab, and click in the form (or report) to place the button. In the Command Button Wizard, select a category from the Categories list, select the desired action from the Actions list, and then click Next. The remaining steps are discussed on the next slide. Copyright © 2017 Pearson Education, Inc.
14
Attach an Embedded Macro to an Event
Type button text Name button To continue: Continue to step through the wizard, and select the option to display text or an image on the command button. If the Text option is selected, type the desired text to display on the button, and click Next. Type the name for the button, and click Finish. Copyright © 2017 Pearson Education, Inc.
15
Attach an Embedded Macro to an Event
Click Property Sheet Click ellipsis Click event A macro also can be added to an existing control manually by clicking the ellipsis in the event box of the control or object in the Property Sheet. To attach an embedded macro to an event, you: Open the object in Design view and open the Property Sheet. Click the control you want to add the macro to, and click in the desired event property box on the Event tab. Click the ellipsis, ensure that Macro Builder is selected, and then click OK. Once the Macro Designer opens, you add actions using the same methods that were used for the stand-alone macro. Click control Copyright © 2017 Pearson Education, Inc.
16
Objective 5: Identify When to Use a Data Macro
In this section, the skills include: Use a Data Macro to Automate Data Entry Skills: Use a Data Macro to Automate Data Entry Copyright © 2017 Pearson Education, Inc.
17
Identify When to Use a Data Macro
Data macros—validate and ensure the accuracy of table data Types of data macros: Event-driven data macros Named data macros Data macros—only associated with table events You can use data macros to validate and ensure the accuracy of data in a table. Two main types of data macros exist: Event-driven data macros are triggered by table events. Named data macros can be run from anywhere in the database. Data macros can only be associated with table events; however, a form that is based on a table that contains a data macro inherits the logic of the table. Copyright © 2017 Pearson Education, Inc.
18
Objective 6: Create an Event-Driven Data Macro
In this section, the skills include: Create a Before Change Data Macro Test a Data Macro Modify a Data Macro Skills: Create a Before Change Data Macro Test a Data Macro Modify a Data Macro Copyright © 2017 Pearson Education, Inc.
19
Create an Event-Driven Data Macro
Click Create Data Macros Select table event Data macros, like stand-alone macros and embedded macros, use the Macro Designer. To attach a data macro to a table event, you: Open the table that will contain the data macro in Design view. Click Create Data Macros in the Field, Record & Table Events group on the Design tab. Click the event to which you want to attach the macro. Add macro actions using the Macro Designer. Save and close the macro. In this example, the Before Change event is being created. To test a data macro, open the table to which the macro was added, and then add, delete, or update a record in order to trigger the macro. We have attached a macro to the Before Change event, open the table, modify the data, and then advance to the next record to save the changes and to trigger the Before Change event. Copyright © 2017 Pearson Education, Inc.
20
Objective 7: Create a Named Data Macro
In this section, the skills include: Create a Named Data Macro Attach a Named Data Macro to a Form Skills: Create a Named Data Macro Attach a Named Data Macro to a Form Copyright © 2017 Pearson Education, Inc.
21
Create a Named Data Macro
Click Create Data Macros Click Create Named Macro In addition to creating data macros that are triggered by events, Access enables you to create named data macros, and you can access these macros from anywhere in the database. In this example, we will create a macro that sends an to the database administrator each time a record in the Employee table is updated. To create a named data macro, you: Ensure that the table is in Design view, click Create Data Macros, and select Create Named Macro from the list. The remaining steps are discussed on the next slide. Copyright © 2017 Pearson Education, Inc.
22
Create a Named Data Macro
Send action To continue: The Macro Designer displays so you can create the macro logic. Save the macro with a descriptive name. Copyright © 2017 Pearson Education, Inc.
23
Objective 8: Understand the Fundamentals of SQL
In this section, the skills include: Create a Simple Query with SQL Statements Skills: Create a Simple Query with SQL Statements Copyright © 2017 Pearson Education, Inc.
24
Understand the Fundamentals of SQL
Structured Query Language (SQL) is the industry-standard language for defining, manipulating, and retrieving the data in a database. When you create a query like the one shown on the slide in Design View, Access generates SQL code to perform the query. Lets look at the query in detail. The table is named Contribution, the query is trying to find contributions from the person whose Social Security number , and the fields that are to be displayed are PayDate, GrossPay 401K Employee, 401KMatch, and 401kTotal. Furthermore, the query is stored in ascending order based on the PayDate. As you can see, there are a lot of specifications required to generate this query. Social Security number Copyright © 2017 Pearson Education, Inc.
25
Understand the Fundamentals of SQL
Select Hyperlink This slide shows the results in Datasheet view. But what underlying SQL code actually implemented this query? Notice that there is a third view and by clicking SQL View, you can see this code. Copyright © 2017 Pearson Education, Inc.
26
Objective 9: Interpret an SQL Select Statement
In this section, the skills include: View the Equivalent SQL Statement in a Query Skills: View the Equivalent SQL Statement in a Query Copyright © 2017 Pearson Education, Inc.
27
Interpret an SQL Select Statement
By clicking SQL, this is the SQL code that is generated by the query. At first glance, the code may seem intimidating, but on the next slide we will compare this code to query previously displayed in Design view. Copyright © 2017 Pearson Education, Inc.
28
Interpret an SQL Select Statement
Looking at the two views, see if you can figure out the meaning of the SQL basic keywords—SELECT, FROM, WHERE, AND ORDER BY. Write down what you think the keywords do before going to the next slide. Copyright © 2017 Pearson Education, Inc.
29
Interpret an SQL Select Statement
Basic SQL keywords: SELECT—specifies the fields to include in the query FROM—specifies the table where the fields can be found WHERE—sets the criteria for the rows in the results ORDER BY—determines how the rows will be sorted The SELECT keyword instructs Access to return the specific fields from one or more tables (or queries). Note: If all fields in a table are required for a query, you can use the asterisk character (*) to select all of the fields in a table. The FROM keyword specifies the table (or tables) that will be searched. The WHERE keyword specifies the criteria that records must match to be included in the results. The ORDER BY keyword is used to sort the records by a certain field in either ascending or descending order. Note: Most SQL statements begin with SELECT and end with a semicolon. Copyright © 2017 Pearson Education, Inc.
30
Objective 10: Use an SQL SELECT Statement as a Record Source
In this section, the skills include: Create an SQL SELECT Statement as a Record Source Skills: Create an SQL SELECT Statement as a Record Source Copyright © 2017 Pearson Education, Inc.
31
Use an SQL SELECT Statement as a Record Source
Let’s look at this report in detail. It may not be obvious, but all the fields are displayed, for all employees, for all dates. See if you can write the SQL statements that would generate this report. SELECT * FROM Contributions; Did you remember to put the semicolon at the end? Copyright © 2017 Pearson Education, Inc.
32
Copyright © 2017 Pearson Education, Inc.
Summary Macro—program to automate a task Two types of macros: Stand-alone Embedded Types of data macros: Event-driven data macros Named data macros Structured Query Language—industry-standard for defining, manipulating, and retrieving database data You can use a macro to create a program to automate a task. There are two types macros: A stand-alone macro is a database object that is created and used independently of other controls or objects. An embedded macro is a macro that executes when an event attached to a control or object occurs. There are two main types of data macros: Event-driven data macros are triggered by table events. Named data macros can be run from anywhere in the database. Structured Query Language (SQL) is the industry-standard language for defining, manipulating, and retrieving the data in a database. Copyright © 2017 Pearson Education, Inc.
33
Copyright © 2017 Pearson Education, Inc.
Questions ? It is important to understand macros and how they automate tasks. You should have a basic understanding how SQL works in the background when working with Access. Are there any questions? Copyright © 2017 Pearson Education, Inc.
34
Copyright Copyright © 2017 Pearson Education, Inc.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.