Access 2007: Advanced Instructor s Edition

Similar documents
Access 2007: Basic Instructor s Edition

PowerPoint 2003: Basic Instructor s Edition

Creating a Crosstab Query in Design View

Microsoft Access 2010

Objective 1: Familiarize yourself with basic database terms and definitions. Objective 2: Familiarize yourself with the Access environment.

PowerPoint 2003: Advanced Instructor s Edition

Microsoft Access 2013

Microsoft Access 2013

Microsoft Certified Application Specialist Exam Objectives Map

Enforce Referential. dialog box, click to mark the. Enforce Referential. Integrity, Cascade Update Related Fields, and. Cascade Delete Related

Microsoft Access 2016

Access - Introduction to Queries

Microsoft Access 2016

Complete Quick Reference Summary

MIS Cases: Decision Making With Application Software, Second Edition. Database Glossary

Microsoft Access XP Queries. Student Manual

When you pass Exam : Access 2010, you complete the requirements for the Microsoft Office Specialist (MOS) - Access 2010 certification.

Access Intermediate

Excel /5.0 rating from ProCert Labs. Basic. Integrated mapping of Microsoft Certified Application Specialist exam objectives

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

PowerPoint Presentation to Accompany GO! All In One. Chapter 13

Introduction to Microsoft Access 2016

Name: Class: Date: Access Module 2

Microsoft Office 2010: Introductory Q&As Access Chapter 2

Access 2016 Essentials Syllabus

Microsoft Access 2013

AUSTIN COMMUNITY COLLEGE CONTINUING EDUCATION. INTRODUCTION TO DATABASE/FILE MANAGEMENT (Access Introduction) (12 hours) ITSW 1053 COURSE SYLLABUS

Table of Contents COURSE OVERVIEW... 5

Skills Exam Objective Objective Number. Creating crosstab queries Create a crosstab query

Access Intermediate

SQL Studio (BC) HELP.BCDBADASQL_72. Release 4.6C

FOCUS ON: DATABASE MANAGEMENT

EXCEL 2002 (XP) FOCUS ON: DESIGNING SPREADSHEETS AND WORKBOOKS

Microsoft Office Access 2013: Part 01. Lesson 04 - Creating Advanced Queries

DOWNLOAD PDF MICROSOFT OFFICE POWERPOINT 2003, STEP BY STEP

Microsoft Access 2013/2016 Course Outlines (version differences will be noted in the outline).

Microsoft Access 2010

Shelly Cashman Series Microsoft Office 365 and Access 2016 Introductory 1st Edition Pratt TEST BANK

AUSTIN COMMUNITY COLLEGE CONTINUING EDUCATION. INTERMEDIATE DATABASE/FILE AMANGEMENT (Access Intermediate) (12 hours) ITSW 1055 COURSE SYLLABUS

Microsoft Office Illustrated Introductory, Building and Using Queries

Access ComprehGnsiwG. Shelley Gaskin, Carolyn McLellan, and. Nancy Graviett. with Microsoft

Access Module 2: Building and Using Queries

Advanced Queries: Moving Beyond the Select Query Instructor: Edwin V. Bonilla

Microsoft Access XP (2002) - Advanced Queries

As your databases continue to evolve, you will need to incorporate advanced queries and reports. This chapter addresses how to create and use action

SAMPLE ICDL 5.0. International Computer Driving Licence. Module 4 - Spreadsheets Using Microsoft Excel 2010

You can also check the videos at the bottom of this page:

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Microsoft Access II 1.) Opening a Saved Database Music Click the Options Enable this Content Click OK. *

More Skills 12 Create Indexes and Establish a One-to-One Relationship. To complete this database, you will need the following file:

Step 1: Create a totals query to show the total cost price and total sale price of the wine for each supplier.

DESIGNING, BUILDING, AND USING DATABASES (BEGINNING MICROSOFT ACCESS, X405.4)

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

IBM Cognos Analytics: Author Reports Advanced (v11.0)

Englische Access 2016-Trainingsskripte für IT Seminare und EDV Schulungen als Word-Dokument zum Ausdrucken und fürs Intranet

Microsoft Access Illustrated. Unit B: Building and Using Queries

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

Desktop Skills Training Catalogue

Importing and Exporting Data

Getting started with Ms Access Getting Started. Primary Key Composite Key Foreign Key

MS-Access : Objective Questions (MCQs) Set 1

To complete this database, you will need the following file:

Business Insight Authoring

Microsoft Excel 2010 Handout

Using Microsoft Access

PowerPoint 2010: Basic Student Manual

Using Microsoft Excel

Level 6 Relational Database Unit 3 Relational Database Development Environment National Council for Vocational Awards C30147 RELATIONAL DATABASE

SAP BusinessObjects Live Office User Guide SAP BusinessObjects Business Intelligence platform 4.1 Support Package 2

Creating a Course Web Site

1-Step Appraisals Personal Property Appraisal Software

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Administering a Database System

Microsoft Access 2007 Module 2

LEVEL 2: INTERMEDIATE FEATURES

Microsoft Word 2010 Introduction to Mail Merge

SAS. Information Map Studio 3.1: Creating Your First Information Map

Microsoft Access 2010

Access 2016: Core Database Management, Manipulation, and Query Skills; Exam

Access Objects. Tables Queries Forms Reports Relationships

AVANTUS TRAINING PTE LTD

SUM - This says to add together cells F28 through F35. Notice that it will show your result is

Working with Data in Microsoft Excel 2010

ICDL & OOo BASE. Module Five. Databases

download instant at

Spreadsheet definition: Starting a New Excel Worksheet: Navigating Through an Excel Worksheet

Advanced Topics in Access: Queries

Access Review. 4. Save the table by clicking the Save icon in the Quick Access Toolbar or by pulling

Learning Worksheet Fundamentals

Career and Technical Education Series: Office Applications II

Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR

Open. Select the database and click. Print. Set printing options using the dropdown menus, then click the

T-SQL Training: T-SQL for SQL Server for Developers

Using Excel to Troubleshoot EMIS Data

Contents. Project One. Introduction to Microsoft Windows XP and Office Creating and Editing a Word Document. Microsoft Word 2003

Database Use & Design

Query Studio Training Guide Cognos 8 February 2010 DRAFT. Arkansas Public School Computer Network 101 East Capitol, Suite 101 Little Rock, AR 72201

Introducing Office

GO! with Microsoft Access 2016 Comprehensive

Formulas, LookUp Tables and PivotTables Prepared for Aero Controlex

Transcription:

Access 2007: Advanced Instructor s Edition

ILT Series COPYRIGHT Axzo Press. All rights reserved. No part of this work may be reproduced, transcribed, or used in any form or by any means graphic, electronic, or mechanical, including photocopying, recording, taping, Web distribution, or information storage and retrieval systems without the prior written permission of the publisher. For more information, go to www.courseilt.com. Trademarks ILT Series is a trademark of Axzo Press. Some of the product names and company names used in this book have been used for identification purposes only and may be trademarks or registered trademarks of their respective manufacturers and sellers. Disclaimer We reserve the right to revise this publication and make changes from time to time in its content without notice.

What is the Microsoft Business Certification Program? The Microsoft Business Certification Program enables candidates to show that they have something exceptional to offer proven expertise in Microsoft Office programs. The two certification tracks allow candidates to choose how they want to exhibit their skills, either through validating skills within a specific Microsoft product or taking their knowledge to the next level and combining Microsoft programs to show that they can apply multiple skill sets to complete more complex office tasks. Recognized by businesses and schools around the world, over 3 million certifications have been obtained in over 100 different countries. The Microsoft Business Certification Program is the only Microsoft-approved certification program of its kind. What is the Microsoft Certified Application Specialist Certification? The Microsoft Certified Application Specialist Certification exams focus on validating specific skill sets within each of the Microsoft Office system programs. The candidate can choose which exam(s) they want to take according to which skills they want to validate. The available Application Specialist exams include: Using Microsoft Windows Vista Using Microsoft Office Word 2007 Using Microsoft Office Excel 2007 Using Microsoft Office PowerPoint 2007 Using Microsoft Office Access 2007 Using Microsoft Office Outlook 2007 What is the Microsoft Certified Application Professional Certification? The Microsoft Certified Application Professional Certification exams focus on a candidate s ability to use the 2007 Microsoft Office system to accomplish industry-agnostic functions, for example Budget Analysis and Forecasting, or Content Management and Collaboration. The available Application Professional exams currently include: Organizational Support Creating and Managing Presentations Content Management and Collaboration Budget Analysis and Forecasting

What do the Microsoft Business Certification Vendor of Approved Courseware logos represent? The logos validate that the courseware has been approved by the Microsoft Business Certification Vendor program and that these courses cover objectives that will be included in the relevant exam. It also means that after utilizing this courseware, you may be prepared to pass the exams required to become a Microsoft Certified Application Specialist or Microsoft Certified Application Professional. For more information To learn more about the Microsoft Certified Application Specialist or Professional exams 1, visit www.microsoft.com/learning/msbc. To learn about other Microsoft Certified Application Specialist approved courseware from Course Technology, visit www.courseilt.com. 1 The availability of Microsoft Certified Application exams varies by Microsoft Office program, program version, and language. Visit www.microsoft.com/learning for exam availability. Microsoft, Windows Vista, Excel, PowerPoint, and Outlook are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The Microsoft Certified Application Specialist and Microsoft Certified Application Professional logos are used under license from Microsoft Corporation.

Contents Introduction iii Topic A: About the manual... iv Topic B: Setting student expectations... ix Topic C: Classroom setup... xiii Topic D: Support... xviii Querying with SQL 1-1 Topic A: SQL and Access... 1-2 Topic B: Writing SQL statements... 1-5 Topic C: Attaching SQL queries to controls... 1-14 Unit summary: Querying with SQL... 1-17 Advanced queries 2-1 Topic A: Creating crosstab queries... 2-2 Topic B: Creating parameter queries... 2-6 Topic C: Using action queries... 2-12 Unit summary: Advanced queries... 2-22 Macros 3-1 Topic A: Creating, running, and modifying macros... 3-2 Topic B: Attaching macros to the events of database objects... 3-6 Unit summary: Macros... 3-12 Advanced macros 4-1 Topic A: Creating macros to provide user interaction... 4-2 Topic B: Creating macros that require user input... 4-11 Topic C: Creating the AutoKeys and AutoExec macros... 4-14 Topic D: Creating macros for data transfer... 4-17 Unit summary: Advanced macros... 4-22 Importing, exporting, and linking 5-1 Topic A: Importing objects... 5-2 Topic B: Exporting objects... 5-12 Topic C: Interacting with XML documents... 5-16 Topic D: Linking Access objects... 5-25 Topic E: Working with Windows SharePoint Services... 5-32 Unit summary: Importing, exporting, and linking... 5-35 Database management 6-1 Topic A: Optimizing resources... 6-2 Topic B: Protecting databases... 6-12 Topic C: Setting options and properties... 6-15 Unit summary: Database management... 6-20 Internet integration 7-1 Topic A: Hyperlink fields... 7-2 Topic B: Working with Outlook 2007... 7-6 Unit summary: Internet integration... 7-8

ii Access 2007: Advanced Course summary S-1 Topic A: Course summary... S-2 Topic B: Continued learning after class... S-4 Glossary G-1 Index I-1

1 1 Unit 1 Querying with SQL Unit time: 40 minutes Complete this unit and you ll know how to: A Use SQL statements and examine them in Access. B Write SQL statements to create queries and sub-queries, and assign aliases to fields. C Create an SQL-specific query and attach it to a command button.

1 2 Access 2007: Advanced Topic A: SQL and Access Explanation Structured Query Language is a standard query language designed to insert, update, delete, and retrieve data from any relational database. It is abbreviated SQL, which is typically pronounced sequel. When you create or modify queries in Design view, Access automatically generates the corresponding SQL statement for that query. Some SQL-specific queries, however, can t be created in Design view, so you need to write their SQL statements manually. For example, union query, which displays the result by combining corresponding fields from two or more tables, is an SQL-specific query. Also, you might find it easier to write more complex queries by using SQL, even if they are possible in Design view. SQL statements An SQL statement contains SQL commands, such as SELECT or UPDATE, and clauses, such as WHERE or HAVING. The syntax for a simple SQL statement is: SELECT FieldName FROM DataSource; In this statement, FieldName is the name of the field from a table or a query, DataSource is the name of the table or query from which the data is to be retrieved, and the query ends with a semicolon. For example, if you want to write a query to view the fields Product ID and Product Name from the table Product, you can write: SELECT ProductID, ProductName FROM Product; The SELECT command specifies the name(s) of the column(s) or field(s) that the query should display. If you want to display all the fields from a table, use the asterisk (*) as shown in the following example: SELECT * FROM Product; The FROM clause specifies the data source for the query. If the data source includes multiple tables, specify their names in the FROM clause. For example, the following query displays data from the Product and OrderItem tables: SELECT Product.ProductID, OrderItem.ItemQuantity FROM Product, OrderItem; In the above example, the table name precedes the field name. This protocol is used to avoid ambiguity if the two tables contain the same field name. A dot or period (.) separates the name of the data source from the field name. SQL commands SQL commands are divided into these categories: Data definition language (DDL) commands create, alter, drop, and truncate objects, such as tables. For example, the CREATE TABLE command creates a table of the specified name. You can specify the fields to be included and also the data type of the fields in the command. ALTER TABLE helps you add a field or column to a table. The DROP table command deletes the table from a database. TRUNCATE removes data from a table without deleting its structure.

Querying with SQL 1 3 Data manipulation language (DML) commands manipulate data in tables. Commonly used DML commands include SELECT, INSERT, UPDATE, and DELETE. SELECT retrieves information from tables. INSERT adds new rows of data to tables. The UPDATE command updates the data in tables. The DELETE command deletes rows from tables. Transaction control commands commit and rollback a transaction. A transaction is a set of logical operations. For example, retrieving data from one table and inserting it into another is a transaction. Such a transaction includes two separate operations, retrieving data and inserting it. The transaction is achieved only when both operations are complete. Commonly used transaction control commands are COMMIT and ROLLBACK. COMMIT updates all changes made by DML commands from the beginning of a transaction. ROLLBACK undoes all the changes made by DML commands during a transaction. Session control commands manage a user session, which gives information about the user who has currently logged on to a system. ALTER SESSION is a session control command that can close a database link. Do it! A-1: Discussing Structured Query Language Exercise 1 Predict the output: SELECT * FROM Retailer; Displays all the records from the Retailer table 2 Predict the output: SELECT ProductID FROM Product; Displays all the values of the Product ID field from the Product table 3 Predict the output: SELECT Product.ProductID, OrderItem.ItemQuantity FROM Product, OrderItem; Displays the Product ID field from the Product table and the ItemQuantity field from the OrderItem table

1 4 Access 2007: Advanced Explanation SQL in Access You can view the syntax of the SQL statements that are automatically created by Access in SQL view. To open a query in SQL view, first open it in Design view and then click the SQL View button on the status bar. In SQL view, as shown in Exhibit 1-1, a period (.) is used to specify the table name along with the field name, a comma (,) separates each field name, and the query ends with a semicolon (;). The SELECT statement specifies fields to be displayed in the query. The FROM clause defines the data source for these fields. Exhibit 1-1: A query in SQL view Do it! A-2: Examining an SQL statement in Access Here s how Here s why 1 Start Access Choose Start, All Programs, Microsoft Office, Microsoft Office Access 2007. Help students locate the current unit folder. If a security warning bar appears, you ll need to add the student data folder and its subfolders to Trusted Locations in the Trust Center. Tell students they can also right-click the query tab and choose SQL View. 2 Open Adv Tables From the current unit folder. 3 In the Navigation Pane, right-click qrysamplequery and choose Design View from the shortcut menu To open the query in Design view. 4 Click (The SQL view button is on the right side of the status bar. You can also click the View button in the Results group and choose SQL View.) The query opens, as shown in Exhibit 1-1. You want to examine the SQL statement for this query. 5 Observe the query window The SELECT statement contains the names of the two fields, lngproductid and strproductname. Each field name is preceded by its table name. The FROM clause is followed by the name of the data source, tblproduct. The query result displays data from the fields, lngproductid and strproductname, from the table tblproduct. 6 On the Design tab, click Run (In the Results group.) To run the query. The query result contains the fields Product ID and Product Name. Product ID is the caption for lngproductid, and Product Name is the caption for strproductname. 7 Close the query

Querying with SQL 1 5 Topic B: Writing SQL statements This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007: # Objective 4.1.5 Create subqueries 4.2.5 Add aliases to query fields Explanation Writing an SQL statement You can enter the SQL statements directly in SQL view. You can also modify queries by editing the SQL statement for that query. If an error occurs in a query, it is sometimes easier to correct the error in the SQL statement than in the design grid. Note: A semicolon ends an SQL statement. Line breaks are used to group parts of the statement logically, so it is easy to read, but they have no effect on the output. To write an SQL statement in Access: 1 Create a new query in Design view. 2 Switch to SQL view. 3 In the query window, write the SQL statement. 4 Save the query with a relevant name.

1 6 Access 2007: Advanced Do it! B-1: Writing an SQL SELECT statement Here s how 1 On the Create tab, choose Query Design Click Close Here s why (In the Other group.) The Show Table dialog box opens. To close the Show Table dialog box. You want to write the SQL statement in SQL view. 2 Switch to SQL View (Click the SQL View button on the status bar.) To open the query window. The window contains the SELECT command. Tell students that they can also copy the text from the file, qry Simple.txt, which is in the current unit folder. 3 Edit the text in the query window to read: SELECT lngretailerid, straddr1, strphone FROM tblretailer; To create a query that displays the fields lngretailerid, straddr1, and strphone from the table tblretailer. Tell students they can also right-click the query tab and choose Save. 4 Click (On the Quick Access Toolbar.) To open the Save As dialog box. Edit the Query Name box to read: qryretailersqlquery Click OK To save the query and to close the Save As dialog box. The query appears in the list on the Navigation pane. If students get an error message, ask them to close the message box and re-examine the query. 5 Click Run The data appears for the fields Retailer ID, Address1, and Phone, which are in the tblretailer table. Retailer ID is the caption for lngretailerid, Address1 is the caption for straddr1, and Phone is the caption for strphone. Close the query 6 Open qryretailersqlquery in Design view (Right-click it and choose Design View.) The query opens in SQL view, because you saved the query in SQL view.

Querying with SQL 1 7 Explanation Specifying criteria in SQL statements One of the main purposes of creating a query is to analyze data. An SQL statement can locate records matching specific conditions by using a WHERE clause. For example, to display the details of a specific retailer, give retailer ID as the condition in the WHERE clause of the query. The following is the syntax of the WHERE clause: SELECT FieldName From DataSource Where criteria; Do it! B-2: Using the WHERE clause Here s how 1 Verify that the qryretailersqlquery query window is active Here s why You want to modify the query by specifying a criterion in the SQL statement. 2 Edit the code to read: Remind students that the semicolon ends the statement; line breaks are for logical clarity. SELECT lngretailerid, straddr1, strphone FROM tblretailer WHERE lngretailerid=0001; To create a query that displays the lngretailerid, straddr1, and strphone fields from the tblretailer table for the retailer whose lngretailerid is 0001. 3 Run the query The query result contains only one record, as there is only a single record with the Retailer ID 0001. 4 Update the query

1 8 Access 2007: Advanced Explanation Objective 4.2.5 Adding field aliases When you query a table, the column names that display in the query results are taken from the tables that the query references. If the table contains captions for the field names, then the query columns use the captions. If not, then the query columns use the field names from the table. If the fields in the table do not have a caption assigned, you can rename a column in the query by assigning an alias to the field. An alias is a name applied to a query column, to replace the default table name for that column. The SELECT statement in a query uses the following syntax for aliases: SELECT FieldName1 as alias1, Fieldname2 as alias2 You can also enter aliases in Design view by inserting the alias in the Field row, followed by a colon, as shown in Exhibit 1-2. Exhibit 1-2: Aliases entered in the Design pane of a query Do it! B-3: Creating aliases Here s how 1 Observe the column names in the query results Close the query Here s why The column names are Retailer ID, Address1, and Phone. These are the captions assigned to these fields in the tblretailer table. You cannot edit the source table while the query is open. 2 Open tblretailer in Design view You ll remove one of the captions. Select strphone Under Field Properties, delete the caption for this field Update the table To save the changes made to its design. 3 Switch to Datasheet view Observe the column heading for the strphone field You removed the caption from this field, so the column heading now uses the field name. Close the table 4 Open qryretailersqlquery in Design view The query opens in SQL view because you saved it in SQL view. You ll assign aliases to change the field names in the query.

Querying with SQL 1 9 5 Edit the first line of code to read: Objective 4.2.5 SELECT lngretailerid as Vendor, straddr1 as Address, strphone as Contact To assign an alias to each of the three fields. 6 Run the query 7 Observe the column headings Only the phone column uses its alias as a column heading, because you removed this field s caption in tblretailer. The other two fields still display their captions from the table, because aliases do not overwrite captions. 8 Switch to Design view Observe the Field row Update and close the query For each field, the aliases appear first in the field row, separated from the field name by a colon.

1 10 Access 2007: Advanced Explanation Displaying matching data from related records To view matching data from multiple tables, you must create a query based on relevant tables and then join them based on a common field. For example, you might need to view the quantity ordered for each product along with its details. To view this data, you need to create a query that displays quantity ordered for a specific product from the OrderItem table and its matching product details from the Product table. The SQL syntax for a query to display matching data from related tables is: SELECT DataSource1.FieldName, DataSource2.FieldName FROM DataSource1, DataSource2 WHERE DataSource1.CommonField=DataSource2.CommonField; In the inner join query shown above, the syntax matches the values of CommonField from DataSource1 with the values of CommonField from DataSource2. The equal sign (=) means that the query result displays only the matching records. Because the CommonField is present in both of the tables, the name of the table must precede the name of the field. Do it! B-4: Displaying matching records from related tables Here s how Here s why 1 Start a new query in Design view On the Create tab, click Query Design. Close the Show Table dialog box Switch to SQL View 2 Edit the text in the SQL window to read: Tell students that they can also copy the text from the file, qry Match.txt, that is in the current unit folder. SELECT tblproduct.lngproductid, tblproduct.strproductname, tblorderitem.sngitemquantity FROM tblproduct, tblorderitem WHERE tblproduct.lngproductid=tblorderitem.lngitemproductid; To create a query to join the tables tblproduct and tblorderitem. This query is set up to match the values of lngproductid in the tblproduct table to the values of lngitemproductid in the tblorderitem table. The query will display lngproductid and strproductname from the tblproduct table and sngitemquantity from the tblorderitem table for the matching records. 3 Save the query as qrymatchquery 4 Run the query To view all records with the matching Product ID from the Product ID and Product Name fields of the tblproduct table and from the Quantity field of the tblorderitem table. 5 Close the query

Querying with SQL 1 11 Explanation Objective 4.1.5 Displaying unmatched records You can write queries to view records from one table that do not have corresponding records in another table. For example, you can view information about retailers who have not placed orders for a specific period of time. In other words, records from the Retailer table for those retailer IDs that do not have a matching entry in the Order table. The syntax for an SQL statement to find unmatched records is: SELECT DataSource1.FieldName FROM DataSource1 WHERE CommonField not in (SELECT DataSource2.CommonField FROM DataSource2); This SQL statement consists of two queries, an inner query and an outer query. An SQL SELECT query inside another query is called an inner query or subquery. This query is enclosed within parentheses. The query that contains this subquery is called an outer query. When you run an SQL statement that consists of inner and outer queries, the inner query executes first and returns the result to the outer query. The outer query then executes against the results. The use of not in sets the outer query to display those records whose values in the CommonField (the field which is present in both tables) do not match the values returned by the inner query. As the CommonField is present in both of the tables, the name of the table must precede the name of the field.

1 12 Access 2007: Advanced Do it! B-5: Finding unmatched records Here s how Here s why Objective 4.1.5 1 Create a new query in SQL view You want to create an unmatched query. 2 Edit the text in the SQL window to read: Tell students that they can also copy the text from the file, qry Nomatch.txt, which is in the current unit folder. Tell students that they can replace not in with in to get matching records. SELECT tblretailer.lngretailerid, tblretailer.straddr1 FROM tblretailer WHERE tblretailer.lngretailerid not in (SELECT tblorder.lngordretailerid FROM tblorder); To create a query that displays the lngretailerid and straddr1 from the tblretailer table. These records do not have matching values in the lngordretailerid field of the tblorder table. 3 Save the query as qrynomatchquery 4 Run the query The inner query executes first and returns the values from the Retailer ID field of the tblorder table to the outer query. The outer query compares these values with the values from the Retailer ID field of the tblretailer table. The values that don t match the values returned by the inner query appear in the result. 5 Close the query The query result contains only one record with the Retailer ID 0011.

Querying with SQL 1 13 Explanation Context-sensitive help You can get context-sensitive help in SQL view by selecting a keyword or placing the insertion point on a keyword and pressing F1. The Access Help window opens, displaying the syntax and other details about the keyword. Do it! B-6: Getting context-sensitive help in SQL Here s how 1 Open qrynomatchquery in Design view Here s why The query opens in SQL view, because it s saved in that view. Tell students that even if they select the entire statement, the help window for the SELECT statement appears. However, to get help on other clauses, they have to select the clauses individually. 2 Place the insertion point in the first SELECT command You want to check the syntax of this statement. 3 Press! To open the Access Help window. The window displays the syntax of the SELECT statement. It also displays each part of the SELECT statement and its description. Close the Access Help window 4 Place the insertion point in the WHERE clause You ll check the syntax of this clause. 5 Press! To open the Access Help window. It displays the syntax and details of the WHERE clause. Close the Access Help window 6 Close the query

1 14 Access 2007: Advanced Topic C: Attaching SQL queries to controls Explanation You can attach SQL queries to a control in a form, so that the user can query data while working with the form. For instance, you can attach an SQL statement to a form button. The query runs when the user clicks the command button. This is especially useful for SQL-specific queries; users cannot create these in Design view, but your form allows them to access these results easily. Creating SQL-specific queries Some of the SQL-specific queries include: Union query Used to combine fields from more than one table or query. For example, to combine data from four tables which contain quarterly sales data. Pass-through query Used to work directly with the tables in other databases. Data-definition query Used to create and alter objects in a database. For example, to create or delete indexes in a database. To create a union query: 1 Create a query in Design view. 2 Close the Show Table dialog box. 3 On the Design tab, click Union to open the SQL window. The title bar of the SQL window shows that it s a union query. 4 Enter the SQL statement for the query in the window. 5 Save and run the query. In the union query result, the field names appear as the column headings, unless you specify a heading for each column in the SQL statement. Attaching an SQL query to a command button When you place a command button on a form, the Command Button Wizard opens. You can use this wizard to assign an action and to set text or a picture on the command button. To attach an SQL query to a command button: 1 Create an SQL query and save it. 2 Open the form in Design view. 3 Click the Command Button control on the Design tab and drag the pointer on the form to create a command button. The Command Button Wizard opens. 4 In the wizard, under Categories, select Miscellaneous to select an action from this category. 5 Under Actions, select Run Query. This sets the action of the command button to run a query. Click Next. 6 Select the query you ve created and click Next. 7 Select a relevant option to display on the command button and click Next. 8 Edit the name of the command button, if necessary, and click Finish to close the wizard. 9 Update and close the form.

Querying with SQL 1 15 Exhibit 1-3: The Command Button Wizard Do it! C-1: Assigning an SQL-specific query to a command button Here s how 1 Create a new Query in design view Here s why To open the Show Table dialog box. You ll create an SQL query and attach it to a command button. 2 Click Close To close the Show Table dialog box. 3 Click (The Union button is in the Query Type group.) To switch to SQL view. Tell students that they can also copy the text from the file, qry Union.txt, which is in the current unit folder. 4 Enter the following text in the SQL window: SELECT * FROM tblretailer WHERE strregion= NY UNION SELECT * FROM tblnewretailer WHERE strregion= NY ; To create a union query that displays all of the fields from the tables, tblretailer and tblnewretailer, that have the value NY in the strregion field. 5 Save the query as qryretailerinfoquery Close the query 6 Open the form frmorder in Design view

1 16 Access 2007: Advanced 7 On the Design tab, click Button In the Controls group. Drag the pointer as shown To create a command button. The Command Button Wizard appears. 8 From the Categories list, select Miscellaneous From the Actions list, select Run Query Click Next You want to select the action of the command button from this category. (As shown in Exhibit 1-3.) To assign the action of running a query when the command button is clicked. A list of queries in the current database appears. 9 Select qryretailerinfoquery You want to run this query when you click the command button. Click Next 10 Select Text To display the command button s caption as text. Edit the box next to Text to read Retailer information Click Next The left part of the dialog box shows a preview of the command button. The command button s name appears. 11 Click Finish The caption appears on the command button. 12 Switch to Form view Click the Form View button on the status bar. 13 Click Retailer information The query result displays the details of retailers in NY. Close the query 14 Update and close the form 15 Close the database

Querying with SQL 1 17 Unit summary: Querying with SQL Topic A Topic B Topic C In this topic, you learned about the syntax of Structured Query Language. You also learned about the various categories of SQL commands. In addition, you learned how to use SQL to query data in Access. In this topic, you learned how to write simple SQL statements. You also learned how to assign aliases to fields. You created a query by using SQL statements to show matched and unmatched records from multiple tables. You also learned how to get context-sensitive help in SQL. In this topic, you learned how to create SQL-specific queries. You also attached the SQL query to a control and ran that query while working with a form. Review questions 1 What is the syntax of a simple SQL statement? SELECT FieldName FROM DataSource; 2 What wildcard character can be used in the SELECT statement to display all of the fields from a table? The asterisk (*) 3 Name the four categories of SQL commands. Data definition language Data manipulation language Transaction control commands Session control commands 4 Which character is used to end an SQL statement? A Colon B Comma C Semicolon D Pound sign 5 In an SQL statement, what is specified in the FROM line? The FROM clause specifies the data source for the query.

1 18 Access 2007: Advanced Independent practice activity 1 Open Practice Create SQL. 2 Write a query to display all of the details about all of the retailers from the tblretailer table. Save the query as qryshowretailersquery. 3 Run the query to view the results. 4 Modify the query, qryshowretailersquery, to display the fields, lngretailerid, strfirstname, and strlastname, from the table tblretailer. 5 Update and run the query. Close the query. 6 Write a query to view the details of orders from the table, tblorderitem, where the sngitemquantity is greater than 50. Save the query as qrybulkorderquery. 7 Create a command button on the form, frmorderitem. 8 Attach the query, qrybulkorderquery, to this command button. The query should run when you click the command button. Set the caption of the command button to View Bulk Orders. 9 Switch to Form view and click the command button to verify that the query runs. 10 Close the query. 11 Update and close the form. 12 Close the database.

2 1 Unit 2 Advanced queries Unit time: 60 minutes Complete this unit, and you ll know how to: A Create crosstab queries to summarize grouped data. B Create parameter queries to view results based on specified criteria. C Create action queries to add, delete, and modify data in tables and to make tables.

2 2 Access 2007: Advanced Topic A: Creating crosstab queries This topic covers the following Microsoft Certified Application Specialist exam objective for Access 2007: # Objective 4.1.4 Create crosstab queries Explanation Objective 4.1.4 Crosstab queries You can display a summary of values based on different types of information. For example, you might need to find the total sales for each product in each region. You can find this by creating a crosstab query, which accepts data from multiple tables and then restructures and displays results for easier analysis. In the example below, the query accepts information from the tables Product and Region and displays results in a spreadsheet form. A crosstab query calculates an average, sum, or other total and then groups the results based on the specified data. One group of data runs down the left side of the datasheet and the other runs across the top. For example, Exhibit 2-1 shows the results of a crosstab query to display the sale of each product to each retailer. In the query result shown in Exhibit 2-1, the row headings, which run down the left side of the datasheet, display the Retailer ID. In the same way, column headings, which run across the top, display the product names. The summarized values are calculated based on each row-column combination. For example, Retailer 0004 has ordered 100 oz. of Asafoetida Powder. This value is calculated by adding the total quantity of Asafoetida Powder ordered by Retailer 0004. Exhibit 2-1: The results of a crosstab query

Advanced queries 2 3 Do it! A-1: Viewing a crosstab query Here s how Here s why Objective 4.1.4 1 Open Adv Queries In the current unit folder. 2 Double-click qryretailercrosstabquery Observe the columns Retailer and Annatto Seed, as shown in Exhibit 2-1 To display the results of this crosstab query. The product names appear as the column headings, and the retailer IDs appear as row headings. The result displays the quantity of products ordered by each retailer. Retailer 0002 has ordered 25 oz. of Annatto Seed, and retailer 0007 has ordered 250 oz. of Annatto Seed. 3 Switch to Design view Click the Design View button on the Status bar. Observe the query design lngordretailerid is the row heading of the query. This field is taken from the table tblorder, and is sorted by ID in ascending order. strproductname is the column heading of the query. This field is taken from the table, tblproduct, and is sorted by name in ascending order. The query is summarized based on the Sum function in the sngitemquantity field. This field contains the quantity of product ordered by each retailer. 4 Close the query

2 4 Access 2007: Advanced Explanation Objective 4.1.4 Crosstab Query Wizard You can use the Crosstab Query Wizard to create a crosstab query. You specify the Row Heading field, Column Heading field, fields on which you want to calculate the summary, and summary function. To create a crosstab query: 1 On the Create tab, click Query Wizard. 2 Select Crosstab Query Wizard and click OK. 3 Under View, select the required option. 4 Select the database object on which you want to create the query and click Next. 5 Add the field to be the row heading and click Next. 6 Add the field to be the column heading and click Next. 7 From the Fields list, select the field on which you want to calculate the summary value. 8 From the Functions list, select the required summary function. 9 Clear the Yes, include row sums box, if necessary, and click Next. 10 Enter the name of the query and click Finish. Exhibit 2-2: The Crosstab Query Wizard Do it! A-2: Using the Crosstab Query Wizard Objective 4.1.4 Here s how 1 Open the query qryretailerorders in Design view Close the query 2 On the Create tab, click Query Wizard Here s why This query displays fields from three tables: strretailername field from tblretailer table, strproductname field from tblproduct table, and sngitemquantity field from tblorderitem table. (In the Other group.) To open the New Query dialog box.

Advanced queries 2 5 3 Select Crosstab Query Wizard Click OK To open the Crosstab Query Wizard. 4 Under View, select Queries The queries in the database appear in the Query list. From the Query list, select Query: qryretailerorders Click Next 5 From the Available Fields list, select strproductname To specify the row heading. 6 Click To add strproductname to the Selected Fields list. Click Next Verify that strretailername is selected The row and column headings appear in the Sample section of the dialog box. To make this field s values the column headings. Click Next 7 Observe the Fields list The sngitemquantity field, which is the only field remaining, is selected. This field contains data you need to summarize. 8 From the Functions list, Select Sum To specify the function based on which you want to summarize the data. The wizard appears as shown in Exhibit 2-2. Click Next 9 Edit the name of the query to read: qryretailerorderscrosstabquery Click Finish To display the results of the crosstab query. The product name appears as the row headings, and the retailer name appears as the column headings. The result displays the total order for each product placed by each retailer. The column Total Of sngitemquantity displays the total order placed for each product. 10 Close the query

2 6 Access 2007: Advanced Topic B: Creating parameter queries This topic covers the following Microsoft Certified Application Specialist exam objective for Access 2007: # Objective 4.2.2 Add criteria to queries Hard-coded criteria Parameters Explanation Objective 4.2.2 Single-criterion parameter queries A parameter query displays results based on user-supplied criteria. When you run a parameter query, a message box prompts you to enter a criterion, which is used by the query. For example, you can create a parameter query that accepts a date from the user and then displays orders placed on that date. Parameter queries can prompt for either a single criterion or for multiple criteria. A single-criterion parameter query prompts you to enter only one criterion when you run the query. For example, you can create a single-criterion parameter query to display the product details of all products that have a unit price greater than a specified value. The unit price is entered at run time. You can specify the text that appears in the dialog box that prompts you to enter the criterion. This text must be under the field for which you want to set the parameter, and it must be enclosed within square brackets, as shown in the following example: >[Unit price is greater than] In the above example, the query must meet the greater than condition. If you specify the value 2 as the parameter, the query result displays all records with a unit price greater than $2. To create a single-criterion parameter query: 1 Create a new query in Design view. 2 Add the required table(s). 3 Add the required fields. 4 In the Criteria row, under the required field, enter the criterion. 5 Save and run the query to display the Enter Parameter Value dialog box. 6 Enter the criterion. 7 Click OK to view the results of the query. Do it! B-1: Creating a single-criterion parameter query Objective 4.2.2 Here s how 1 Create a new query in Design view Here s why On the Create tab, click Query Design. 2 Select tblproduct (In the Show Table dialog box.) You ll make a parameter query based on this table.

Advanced queries 2 7 3 Click Add To add this table. 4 Click Close To close the Show Table dialog box. 5 Click inside the first cell in the Field row Click the drop-down arrow Select lngproductid (If necessary.) A drop-down arrow appears. A list containing the fields of the table, tblproduct, appears. To add this field to the design grid. The tblproduct table appears in the first cell of the Table row. 6 Add the strproductname and the curunitprice fields to the next two cells in the Field row 7 In the third cell of the Criteria row, enter >[Unit price is greater than] 8 Save the query as qryunitpricequery Close the query You ll display the records that have a unit price greater than the specified value. In this criterion, greater than (>) is the condition that must be met by the query, and the text inside the square brackets is the prompt that appears in the dialog box. 9 Double-click qryunitpricequery To run the query. The Enter Parameter Value dialog box appears before the query opens. It contains the text that you specified. 10 Enter 1.5 To specify the criterion for the query. Click OK To view the query results. The records that display all have a unit price greater than $1.50. 11 Switch to Design view 12 Run the query You want to specify a new parameter. The Enter Parameter Value dialog box appears. 13 Enter 2 To specify the criterion for the query. Click OK The display returns to Datasheet view, and the result now displays only those records with a unit price greater than $2. 14 Close the query

2 8 Access 2007: Advanced Explanation Objective 4.2.2 Multiple-criteria parameter queries A multiple-criteria parameter query prompts for more than one value and displays the query results based on these values. For example, if you want to create a multiplecriteria parameter query to display orders that are placed between two dates, you can enter the two dates at run time. To create a multiple-criteria parameter query: 1 Create a new query in Design view. 2 Add the required table(s). 3 Add the required fields. 4 In the Criteria row, under the required field, enter the criteria to accept more than one value. 5 Save and run the query to display the Enter Parameter Value dialog box. 6 Enter the criteria and click OK each time the dialog box appears. Do it! B-2: Creating a query with multiple parameters Objective 4.2.2 The names in the list may be difficult to read because of their length. Tell students that if they widen a column in the design grid, the dropdown list box will expand to match it. Here s how 1 Create a new query in Design view 2 Select the tables tblorder and tblorderitem Observe the relationship between the two tables 3 From tblorder, add lngorderid, dtmorddate, and lngordretailerid to the design grid 4 From tblorderitem, add lngitemproductid to the design grid 5 In the second cell of the Criteria row, enter: Here s why You ll create a multi-criteria parameter query. (In the Show Table dialog box.) Select these two tables, click Add, then click Close. The tblorder and tblorderitem tables have a one-to-many relationship between them. This relationship ensures that each record in tblorderitem has a corresponding record in tblorder, and each record in tblorder can have multiple records in tblorderitem. Between [Start date] and [End date] 6 Save the query as qryorderdatesquery To display the details of orders placed between the specified Start date and End date.

Advanced queries 2 9 7 Run the query The Enter Parameter Value dialog box appears, prompting you to enter the start date. 8 In the Start date box, enter 1-1-2006 Click OK 9 In the End date box, enter 2-1-2006 Click OK To specify the start date from which you want to view the order details. Another Enter Parameter Value dialog box appears, prompting you to enter the end date. To specify the end date up to which you want to view the order details. To close the Enter Parameter Value dialog box and to display the query results in Design view. Only records with order dates in January of 2006 display. 10 Switch to Design view 11 Run the query Now you can specify different parameters. The Enter Parameter Value dialog box appears. 12 Enter 2-1-2006 Click OK 13 Enter 2-10-2006 Click OK To display the query results, which include only those records with order dates in the first ten days of February. 14 Close the query

2 10 Access 2007: Advanced Explanation Objective 4.2.2 Wildcards in parameter queries You can create a parameter query that permits you to leave the parameter blank at run time. Then, the query result displays all records from the table. If you don t want to search for a specific value, you can use an asterisk (*) to specify a wildcard as part of the parameter. For example, if you want to search for all employees whose last names begin with a specific letter, you can use the asterisk wildcard, as shown in the following expression: Like [First letter of name] & * The query results then display all records where the last name begins with the specified letter. The ampersand (&) operator is used to combine two fields containing text values. In the above expression, it combines the first letter of the name with the rest of the text retrieved by the wildcard character. To create a query using a wildcard: 1 Create a new query in Design view. 2 Add the required table(s). 3 Add the required fields. 4 In the Criteria row, under the required field, enter the criterion containing the wildcard. 5 Save and run the query to display the Enter Parameter Value dialog box. 6 Enter the criterion, if necessary. 7 Click OK to view the results of the query.

Do it! B-3: Using a wildcard in a parameter query Advanced queries 2 11 Here s how Here s why Objective 4.2.2 1 Create a new query in Design view 2 Add the tblorder and tblorderitem tables 3 In the first cell of the field row, select tblorderitem.* from the field list 4 In the second cell of the Field row, add dtmorddate To add all of the fields of the table to the design grid. This selection displays all of the fields of the tblorderitem in the query results. From tblorder table. Tell students that if they enter 1 as the parameter, the orders placed in the months of January, October, November, and December appear. 5 In the second cell of the Criteria row, enter: Like [For the month] & * 6 Save the query as qryordersbymonthquery To display the details of orders placed in the month(s) starting with the number you specify at run time. 7 Run the query The Enter Parameter Value dialog box appears. 8 Enter 10 Click OK The query results show the order details for all products that were ordered in October. 9 Switch to Design view 10 Run the query You want run the query without specifying any parameter. The Enter Parameter Value dialog box appears. Click OK To run the query without specifying any criterion. The query result displays all of the records from the tblorderitem table and the corresponding Order Date from the tblorder table. 11 Close the query 12 Close the database

2 12 Access 2007: Advanced Topic C: Using action queries This topic covers the following Microsoft Certified Application Specialist exam objective for Access 2007: # Objective 4.1.3 Create action queries Make table Insert Append Delete Explanation Action queries are queries that perform certain actions on several records in a single operation. For example, you can use an action query to add records from one table to another. The following are the types of action queries: Append query Used to append data from one table to another Delete query Used to delete records from tables based on specified criteria Update query Used to update data in different tables at the same time Make Table query Used to create a table from the result of a query Append queries Objective 4.1.3 An append query is used when you want to append records from one table to another based on some criteria. To add records to a table by using an append query: 1 Create a query to display the results that you want to append to a table. 2 On the Design tab, in the Query Type group, click Append. 3 From the Table Name list, select the required table. 4 Select the Current Database option and click OK. 5 Save, close, and run the query. Warning messages appear stating that the query will modify and will append the records to the table. 6 Click Yes to append the records. Do it! C-1: Adding records to a table with an append query Here s how Here s why Objective 4.1.3 1 Open Append Queries From the current unit folder. 2 Open tblneworder To view the contents of this table. The table contains two records. Close the table 3 Open tblorder To view the contents of this table. The table contains multiple records. Close the table

Advanced queries 2 13 4 Create a query in Design view You will to create an append query. 5 Add the table tblneworder and close the Show Table window 6 In the first cell of the Field row, from the list, select tblneworder.* You ll append data from this table. To append all records from tblneworder. 7 On the Design tab, click Append (In the Query Type group.) The Append dialog box appears. You ll select the type of query. 8 From the Table Name list, select tblorder Verify that Current Database is selected Click OK 9 Save the query as qryappendneworderquery To append all of the records from tblneworder to tblorder. You ll append records to tblorder in the current database. To close the Append dialog box. The query is added to the Navigation Pane, and it has an append icon. 10 Close the query 11 Run the query The Microsoft Office Access dialog box appears stating that you are about to run an append query that will modify data in your table. 12 Click Yes The Microsoft Office Access dialog box appears stating that you are about to append two rows. Click Yes To append the records. 13 Open tblorder To view the contents of the table. The two records from tblneworder were added to the end of this table. Close the table Close the database

2 14 Access 2007: Advanced Explanation Objective 4.1.3 Delete queries You can delete a group of records from multiple tables based on the same criteria. For example, you might need to cancel a specific order from the Order table and its corresponding records from the OrderItem table. To do so, you can create a delete query that deletes records from both tables. Here s the basic procedure: 1 Create a query in Design view. 2 Add the required table(s). 3 On the Design tab, in the Query Type group, click Delete. 4 Add the field from the required table on which you want to specify the criteria. 5 Specify the required delete criteria. 6 Add all of the fields of the table from which you want to delete records based on the specified criteria. Close the query. 7 Run the query. Warning messages appear stating that the query will modify and will append the records to the table. 8 Click Yes twice to delete the records. Close the query. 9 Remove the table from which the records are deleted. 10 Run the query again to delete the record from the second table. Do it! C-2: Deleting records with a delete query Here s how Here s why Objective 4.1.3 1 Open Adv Queries From the current unit folder. 2 Open tblorderitem The table has more than 60 records. Close the table 3 Create a query in Design view 4 Add tblorder and tblorderitem 5 On the Design tab, click Delete The button is in the Query Type group. 6 Double-click the join line between tblorder and tblorderitem, as shown To open the Join Properties dialog box.

Advanced queries 2 15 7 Click the third selection, as shown To display all records from tblorderitem and only the matching records from tblorder. Click OK To close the Join Properties dialog box. 8 From tblorder, add lngorderid 9 In the first cell of the Delete row, verify that Where appears 10 In the first cell of the Criteria row, enter 9 11 In the second cell of the Field row, from the list, select tblorderitem.* To specify the criterion to delete records. Records with an Order ID of 9 will be deleted from the table tblorderitem. To include all records from tblorderitem in the query. You ll delete all the records from tblorderitem that meet the specified criterion. 12 In the second cell of the Delete row, verify that From appears 13 Save the query as qrydeleteorderquery It appears in the Navigation Pane with a delete query icon. 14 Switch to Datasheet view To view the records to be deleted by the query. Each has an Order ID of 9. 15 Close the query 16 Run the query The Microsoft Office Access dialog box appears stating that the query will modify data in the table. Click Yes The Microsoft Office Access dialog box appears stating that you are about to delete 4 rows. Click Yes

2 16 Access 2007: Advanced 17 Open tblorderitem The table now has fewer than 60 records. Sort the table by the Order ID column Observe the Order ID column Click the arrow beside the column heading and choose Sort Smallest to Largest. All records with an Order ID of 9 have been removed. Close tblorderitem 18 Open tblorder The record for Order ID 9 remains in the table because you can t delete records from two tables simultaneously. You need to run the query twice to delete records from both of the tables. Ensure that students don t double-click the query. Close tblorder 19 Open qrydeleteorderquery in Design view Click the asterisk in tblorderitem item as shown Do not save changes. Now, you want to delete the record that contains 9 as Order ID from the tblorder table. Press d 20 Update and close the query 21 Run the query Click Yes Click Yes To select the table. You want to remove this table from the query. To remove this table from the query. To acknowledge the warnings and delete the row. 22 Open tblorder The record with Order ID 9 is deleted from the table. Close tblorder

Advanced queries 2 17 Explanation Objective 4.1.3 Update queries An update query changes records in a table. You can enter the parameters for this query by using the Query Parameters dialog box, as shown in Exhibit 2-3. This dialog box contains two columns. You enter the name of the parameter in the Parameter column and its corresponding data type in the Data Type column. These parameters are accepted in the order they re entered in the dialog box. For example, if you need to accept the Retailer ID before accepting the Phone number, you need to enter the ID parameter before the Phone number parameter in the Query Parameters dialog box. To modify records by using an update query: 1 Create a query in Design view. 2 Add the required table(s). 3 Add the required fields. 4 On the Design tab, click Update Query. 5 On the Design tab, click Parameters. The Query Parameters dialog box appears. 6 In the Parameter column, enter the parameters. 7 In the Data Type column, enter the data types for the parameters. 8 Click OK to close the Query Parameters dialog box. 9 Enter the required parameters in the Criteria row and in the Update To row. 10 Save, close, and run the query. 11 Click Yes to close the warning message. 12 Enter the value and click OK each time the Enter Parameter Value dialog box appears. 13 Click Yes to update the row. Exhibit 2-3: The Query Parameters dialog box

2 18 Access 2007: Advanced Do it! C-3: Modifying records with an update query Here s how Here s why Objective 4.1.3 1 Create a query in Design view You ll create an update query. 2 Add the table tblretailer 3 From tblretailer, add lngretailerid, strphone, and strfax You ll update phone and fax data. 4 On the Design tab, click Update (The Update button is in the Query Type group.) The Update To row is added. 5 On the Design tab, click (In the Show/Hide group.) To open the Query Parameters dialog box, as shown in Exhibit 2-3. You ll assign parameters to the query. Under Parameter, in the first cell, enter ID Under Data Type, click inside the first cell From the drop-down list, select Long Integer To specify the first parameter as ID. The data type Text and a drop-down arrow appear. To specify the data type of the parameter as Long Integer. Fill the next two rows as shown To specify the second and third parameter as Phone and Fax and their data types as Text. Click OK 6 Under lngretailerid in the Criteria row, enter [ID] 7 Under strphone in the Update To row, enter [Phone] To close the dialog box. To specify the criterion of the query as lngretailerid field. To update the strphone field based on the input received from the user. 8 Under strfax in the Update To row, enter [Fax] To update the strfax field based on the input received from the user.

Advanced queries 2 19 9 Save the query as qryupdateretailerquery 10 Close the query 11 Run the query The Microsoft Office Access dialog box prompts that you will modify data in your table. Click Yes To close the dialog box and run the query. The Enter Parameter Value dialog box appears. 12 Enter 0001 You ll modify the Phone field and the Fax field of Retailer 0001. Click OK The ID is accepted and the Phone prompt appears. 13 Enter (532) 231-5492 To specify the new phone number. Click OK The phone number is accepted and the Fax prompt appears. 14 Enter (532) 231-5583 To specify the new fax number. Click OK Click Yes To close the dialog box. The Microsoft Office Access dialog box appears, warning that you are about to update one row. To update the row. 15 Open tblretailer The Phone field and Fax field of the Retailer ID 0001 is updated with the information you entered. Close the table 16 Close the database

2 20 Access 2007: Advanced Explanation Objective 4.1.3 Make Table queries A Make Table query is used to create a table based on a set of records that are the results of a query. For example, by using a Make Table query, you can create a table that stores the results of another query, such as the Employee and Supervisor details. To create a table by using a Make Table query: 1 In Design view, open the query that displays the desired records. 2 On the Design tab, click Make Table. 3 In the Table Name box, enter the required table name. 4 Select the Current Database option and click OK. 5 Update, close, and run the query to display a warning message. 6 Click Yes twice to create the new table.

Advanced queries 2 21 Do it! C-4: Creating a Make Table query Here s how Here s why Objective 4.1.3 1 Open HR From the current unit folder. 2 Open qryexamplequery You ll convert this query to a make table query. This query contains details for employees whose department code is AD. Switch to Design view 3 On the Design tab, click Make Table (In the Query Type group.) To open the Make Table dialog box. 4 In the Table Name box, enter tblemployeead To specify the name of the new table. Verify that Current Database is selected Click OK 5 Update and close the query 6 Run the query A warning appears. Click Yes Click Yes To run the query. To paste rows into a new table. 7 Open tblemployeead The records in the table are the same as the query results. Close the table Close the database

2 22 Access 2007: Advanced Unit summary: Advanced queries Topic A Topic B Topic C In this topic, you learned that crosstab queries are used to display summaries of values based on information type. You also learned how to create crosstab queries. In this topic, you learned how to create parameter queries that accept values from the user and display data according to the specified values. You learned how to create single-criterion, multiple-criteria, and wildcard-based parameter queries. In this topic, you learned how to create action queries that perform certain actions on several records in a single operation. You learned how to create append, delete, update, and make table queries. Review questions 1 Why would you create a crosstab query? If you want to display a summary of values based on data from multiple tables. The crosstab query restructures the results and displays them for easy analysis. 2 What type of query enables the user to provide criteria when the query is running? A Action query B Parameter query C Crosstab query D Make table query 3 What are the two types of parameter queries that can be created? Single-criterion and multiple-criteria 4 What type of query is used to find records based on a specific criteria and act on those records? Action queries 5 Name the four types of action queries. Append, Delete, Update, and Make Table

Independent practice activity Advanced queries 2 23 1 Open Practice Adv Queries. 2 Create a crosstab query based on qryproductorderquery. The row headings should be product names and the column headings should be order dates. The order dates should be grouped by month. The data in the quantity field is to be summarized based on the Sum function. Do not include row sums. Save the query as qryproductordercrosstabquery and close it. Run the query. 3 Create a single-criterion parameter query from the tblorder table. The query should display records containing order ID, order date, and retailer ID fields that have an order date greater than a specified value. Save the query as qrydatequery and close it. Run the query, enter the date 3-7-2006, and observe the results. 4 Create a multiple-criteria parameter query from the tblproduct table. The query should display only records containing product names and stock available and that have the stock value between two specified values. Save the query as qrystockquery and close it. Run the query, enter the values 500 and 1000, and verify the results. 5 Create a parameter query by using a wildcard character. This query should be created based on the table tblretailer, and it should display the retailer ID, retailer name, and the first address. The query should accept a character and display the names of the retailers beginning with that character. Save the query as qryretailernamequery and close it. Run the query, enter the character S, and verify the results. 6 Create a query to append all data from the tblnewretailer table to the tblretailer table. Save the query as qryappendnewretailerquery and close it. Run the query. Open the tblretailer table and verify the results. Close the table. 7 Create an update query based on tblorderitem to change the discount percentage on all orders with the specified ID. Save the query as qryupdatediscountquery and close it. Run the query. Enter the ID as 4 and the discount as 20. Open the tblorderitem table and verify the results. (Hint: Specify criteria under the lngitemproductid field and update the field, lngdiscount.) Close the table. 8 Create a new table by using a make table query. The table should be based on the query qryproductorderquery. Name the table tblmaketable. Update and close the query. Run the query. Verify the results by opening the tblmaketable in Datasheet view. 9 Close the table and the database.

2 24 Access 2007: Advanced

3 1 Unit 3 Macros Unit time: 40 minutes Complete this unit, and you ll know how to: A Create and run macros to automate tasks. B Attach macros to events of database objects.

3 2 Access 2007: Advanced Topic A: Creating, running, and modifying macros Explanation You can automate repetitive tasks by using macros. A macro contains one or more actions that you group together to accomplish a task automatically. You can use macros to automate almost any repetitive task, such as printing a report or opening a form. Macro window You can create and modify macros by using the Macro window. To open the Macro window, activate the Create tab, click the Macro button, and choose Macro. The tab title of the Macro window has a macro icon followed by Macro1. This is the default name of the macro. You can save the macro with a different name or leave the default. A sample macro is shown in Exhibit 3-1 in Design view. The upper part of the Macro window has two columns, the Action and Comment columns. The Action column contains the list of actions that the macro performs. You can select a suitable action from the list to be executed by the macro. For example, if you want the macro to display a message box when you open a specific form, you can select MsgBox from the Action list. For each action you select in the Action column, you can give a corresponding comment that describes the action in the Comment column. Comments are optional. The lower part of the Macro window has the Action Arguments section. This section is specific to the action that you select in the Action column. For example, if the macro s action is set to display a message box, you need to specify the text of the message under the Action Arguments section. Some components of the Access environment have been moved or arranged for the exhibit. It will look different on students computers. Exhibit 3-1: A sample macro in Design view

Macros 3 3 When you open a macro, the Macro Tools Design tab opens, as shown in Exhibit 3-2. This ribbon tab contains buttons for performing some common actions on macros. Exhibit 3-2: The Macro Tools Design tab Creating and running macros To create and run a macro: 1 On the Create tab, click Macro and choose Macro. 2 Place the insertion point in the first cell of the Action column. 3 Enter the action for the macro to perform, or select an action from the list. 4 In the Comment column, enter comments describing the action, if required. 5 Under Action Arguments, enter the relevant data. The arguments vary, depending on the action you selected in the Action column. 6 On the Design tab, click Run. 7 Save and close the Macro window.

3 4 Access 2007: Advanced Do it! A-1: Creating and running a macro Here s how Here s why 1 Open Create Macro From the current unit folder. Tell students that if they click the bottom portion of this button, a list appears. They should choose Macro from the list. 2 On the Create tab, click Macro The Macro window appears. You ll create a new macro to automate the task of adding employee information to the tblemployee table. 3 In the first cell under Action, click the drop-down arrow To display a list of actions from which you can select an action for the macro. From the Action list, select OpenTable 4 Under Action Arguments, click inside the Table Name box, then click the drop-down arrow From the list, select tblemployee 5 In the View box, verify that Datasheet is selected 6 From the Data Mode drop-down list, select Add 7 Save the macro as mcropenemployee To set the macro action for opening a table. When you run this macro, the macro action opens a table that you specify in the Action Arguments section. A list of tables in the current database appears. This specifies that the tblemployee table will open when this macro runs. This ensures that the table opens in the Datasheet view. To open the tblemployee table in append mode. The Macro Window should resemble Exhibit 3-1. 8 On the Design tab, click Run To run the macro. The tblemployee table opens in Datasheet view in the append mode. Now you can add the details of the new employees. Tell students that the Emp ID field is an Autonumber field, and that they need to edit the Hire Date field, which defaults to today s date. 9 Enter details for two employees as shown below Update and close the table Close the Macro window 10 Open tblemployee To open the table. The 26th and 27th records you added appear in the table. 11 Close the table

Macros 3 5 Explanation Modifying macros To modify an existing macro, open the macro in Design view. Then edit the Action, Comment, and Action Arguments values to suit your needs. To add a new action to an existing macro: 1 Open the macro in Design view. 2 In the Action column, select an action for the macro. 3 Under Action Arguments, enter the values that you want. Do it! A-2: Modifying a macro Here s how 1 Open mcropenemployee in Design view 2 From the first cell under Action, select MsgBox from the dropdown list. 3 Under Action Arguments, in the Message box, enter Click OK to edit records. Here s why You ll modify the first action of the macro and then add another action to it. To set this as the first action. The message box will display this message when you run the macro. 4 In the second cell under Action, select OpenTable To set the second action. In Table Name, select tblemployee In Data Mode, select Edit (If necessary.) The table will open in edit mode. 5 Update the macro Click the Save button on the Macro Design toolbar. 6 Run the macro A message box appears, prompting you to click OK to edit records. 7 Click OK To close the message box. The tblemployee table opens. 8 Edit the Emp HR# field of the last record to read 11-63424 Close the table Close the Macro window

3 6 Access 2007: Advanced Topic B: Attaching macros to the events of database objects Explanation You can attach macros to object events. An event is a specific action that is associated with a given object or control and is usually a result of user action, such as clicking the mouse button or opening a form. When you associate a macro with an event, the macro executes automatically whenever that specific event occurs. Form events and event properties To attach a macro to a specific event of the object or control, open its Property Sheet and set the macro to the relevant event property. The Property Sheet of each database object or control contains properties associated with that database object or control. These properties determine the behavior and characteristics of that object or control. For example, if you want to run a macro when you open a form, you open the Property Sheet for that form and set the macro to the Open event of the form. The following table describes some of the form events: Event Event property Event occurs when you Click On Click Click a form. DblClick On Dbl Click Double-click a form. Close On Close Close a form. Resize On Resize Change the size of a form. Open On Open Open a form. Attaching a macro to the Open event If you want a macro to run immediately after a database object opens, you need to attach it to the Open event of the object. To attach a macro to the Open event of a form: 1 Open the form in Design view. 2 Open the form s Property Sheet to set the necessary form property. 3 Activate the Event tab, as shown in Exhibit 3-3. 4 Click the drop-down arrow in the On Open box to display a list of macros. 5 Select Form from the list box on the top of the Property Sheet, if the On Open event is not present in the events list. 6 Select the macro you want to run when this form opens. 7 Close the Property Sheet.

Exhibit 3-3: The Event tab on the Property Sheet of a form Macros 3 7

3 8 Access 2007: Advanced Do it! B-1: Attaching a macro to the Open event of a form Here s how 1 Open mcremployee in Design view Here s why This macro shows a message box with the text, You cannot modify the data in this form. You ll attach this macro to the Open event of a form, so that the message displays when the user opens the form. Close the macro 2 Open frmemployee in Design view Tell students they can also right-click the form selector and choose Properties from the context menu. 3 On the Design tab, click Property Sheet (In the Tools group.) To open the form s Property Sheet. Activate the Event tab 4 From the On Open drop-down list, select mcremployee You ll associate the macro to an event. To attach this macro to the Open event of this form. Close the Property Sheet 5 Switch to Form view (Click the Form View button on the status bar, or click the View button on the Design tab and choose Form View.) A message box appears, stating that you cannot modify the data in this form. Click OK To close the message box. 6 Update and close the form

Macros 3 9 Explanation Attaching macros to command buttons Attaching a macro to a command button s On Click event causes the macro to run when a user clicks the button. To attach a macro to an event of a command button: 1 Open the form in Design view. 2 On the Design tab, click Button. 3 Drag the pointer on the form to create a command button of the required size. 4 Click Cancel to close the Command Button Wizard, as you want to attach a macro to this command button manually. 5 Display the Property Sheet. 6 Activate the Format tab and enter a caption for the command button. 7 Activate the Event tab to attach a macro to an event. 8 Click inside the On Click box and select the required macro from the list. 9 Close the Property Sheet. 10 Update and close the form. To display a picture on the command button, open its Property Sheet and set its Picture property in the Format tab. To display text, set the Caption property of the command button. Exhibit 3-4:The frmproduct form

3 10 Access 2007: Advanced Do it! B-2: Attaching a macro to a command button Here s how 1 Open mcropenretailers in Design view Under Action Arguments, observe the Form Name box Here s why You ll attach this macro to a command button on the frmproduct form. The first cell of the Action column contains OpenForm. This action opens the specified form. This indicates that the frmretailer form will open when you run the macro. Close the macro 2 Open the form frmproduct in Design view 3 On the Design tab, Click Button To add a command button to the form. Place the pointer below the text box, memproddescr, and drag, as shown The Command Button Wizard appears. Click Cancel To close the Command Button Wizard. 4 Open the Property Sheet If necessary. Activate the Format tab Edit the Caption box to read View retailers Press e You ll set the caption property in this tab. To make this the command button s caption. To update the button caption. 5 Activate the Event tab You ll attach a macro to an event of this command button. 6 From the On Click event list, select mcropenretailers To attach the mcropenretailers macro to the Click event of this command button. When you click this command button, this macro opens the form, frmretailer. Close the Property Sheet 7 Switch to Form view The frmproduct form appears in the Form view, as shown in Exhibit 3-4. Click View retailers To open the frmretailer form. You can click the button to view information about retailers while entering product details.

Macros 3 11 8 Update and close both of the forms 9 Close the database

3 12 Access 2007: Advanced Unit summary: Macros Topic A Topic B In this topic, you learned how to create and run a macro to automate simple tasks. You also learned how to modify a macro. In this topic, you learned how to attach a macro with the Open event of a form. You also learned how to attach a macro to a command button on a form. Review questions 1 Why would you create a macro? To automate repetitive actions 2 What is the procedure to create a new macro? a On the Create tab, click Macro and then choose Macro. b c d e In the Action column, select the action to be performed. In the Comment column, enter a description of the action. Under Action Arguments, enter the relevant data. Click the Save button on the Macro Design toolbar. 3 How do you edit an existing macro? Open it in Design view. 4 In Access, what is an event? A specific action that is associated with a given object or control, and is usually a result of user action, such as clicking the mouse or opening a form. 5 Which of the following is used to run a macro that opens a form based on a user action? A Attach a macro to the Open event. B Attach a macro to a command button. C Create a self-executing macro. D Create a form macro.

Independent practice activity Macros 3 13 1 Open Practice Macros from the current unit folder. 2 Create a macro to open the tblretailer table. The table should open in the Edit mode. (Hint: Use the Action Arguments in Design view.) 3 Save this macro as mcreditretailer. 4 Run the macro to open the tblretailer table and edit the Retailer Name for the last record to read Spice Center. Close the table. 5 Modify the macro to add another action that displays the message, Click OK to add details for a new customer before opening the table. 6 Update and run the macro to verify the modification and then close the table. Close the Macro window. 7 Create a new macro to open the form frmorder. Save the macro as mcropenorder. (Hint: Use the action OpenForm.) Close the Macro window. 8 Open the form frmretailer in Design view. Add a command button to the form. 9 Change the caption of the command button to read View orders. 10 Attach the macro, mcropenorder, to the command button. The macro should run when you click the command button. (Hint: Use the Event tab in the Property Sheet of the command button.) 11 Switch to Form view. Click the command button to verify that frmorder opens. Update and close the forms. 12 Close the database.

3 14 Access 2007: Advanced

4 1 Unit 4 Advanced macros Unit time: 80 minutes Complete this unit, and you ll know how to: A Create data validation and data-entry macros. B Create macros that run parameter queries. C Create the AutoKeys and AutoExec macros. D Create macros to import and export database objects.

4 2 Access 2007: Advanced Topic A: Creating macros to provide user interaction Explanation You can use macros to perform data entry. For example, if you are entering the order details into a database, you can create a macro that displays the system date if the date field is left blank. You can also use macros to validate the data you enter. For example, while entering the details of orders, if you forget to enter the customer s name, a message alerting you to enter the name could appear before you proceed to the next record. Data validation macros You can create a macro to validate data by specifying criteria in the Condition column of the Macro window. To view the Condition column, click the Conditions button on the Macro Tools Design tab. You can use this column to specify conditional expressions that are evaluated as either true or false, as shown in Exhibit 4-1. If the condition evaluates to true, the macro action in that row is executed. Some components of the Access environment have been moved or arranged for the exhibit. It will look different on students computers. Exhibit 4-1: The Design view of mcrrequireaddress macro containing a condition

Advanced macros 4 3 The following table describes a few macro actions you can use for data validation: Action CancelEvent GoToControl GoToRecord Description Cancels the event that initiated the macro. Places the insertion point in the specified control on a form. Makes the specified record active in a form, data table, or query result. You associate macros with the events of database objects and controls. The following table describes a few events that occur when you enter data in a form: Event Event property Event occurs GotFocus On Got Focus When a control receives focus. LostFocus On Lost Focus When the user shifts focus from one control to another. AfterUpdate After Update When the data in a control on a form is changed and the changes are updated. BeforeUpdate Before Update Before the changes made to the data in a control on a form are updated.

4 4 Access 2007: Advanced Ensuring data entry You can create macros to ensure that users don t leave specific fields blank while entering data. To this end, you specify the Is Null operator as the condition of the macro. A field has Null value when it s left blank. If the specified field has Null value, the macro alerts the users to enter data before proceeding to the next field, as shown in Exhibit 4-2. To create a macro that ensures that users enter data in a specified field: 1 Open a new macro in Design view. 2 On the Design tab, click Conditions. 3 In the Condition column, enter the relevant criteria. 4 In the Action column, specify the required action. This action is executed if the criterion specified in the Condition column is true. 5 Open the Property Sheet of the form and click the Event tab. 6 Attach the macro to the relevant event. 7 Switch to Form view. 8 Add a new record to the form to test the macro. Exhibit 4-2: The frmretailer form, displaying a message box

Advanced macros 4 5 Do it! A-1: Creating a data validation macro Here s how Here s why 1 Open Adv Macros From the current unit folder. 2 Create a new macro You ll create a macro that ensures that the user enters a value in the Address field of the frmretailer form. 3 On the Design tab, click Conditions The Condition column appears in the Macro window. You can use this column to set a condition for the corresponding action. Tell students that the ellipsis is used to specify the same condition for multiple actions. Tell students that they might need to scroll down. Under Condition, in the first cell, enter [straddr1] Is Null In the first cell under Action, select CancelEvent Under Comment, in the first cell, enter Won t save the record if address is not entered. 4 In the second cell under Condition, enter In the second cell under Action, select MsgBox Under Comment, in the second cell, enter Prompts to enter information. Under Action Arguments, in the Message box, enter Information is incomplete. Please enter the complete address. This is the condition against which data is checked. This evaluates to true if the user doesn t enter data in the Address1 field. This action cancels the event that initiated the macro, if the specified condition is true. This comment describes the action specified in the Action column. This sets the first condition as the condition for the second action.

4 6 Access 2007: Advanced 5 In the third Condition cell, enter In the third cell, from the Action list, select GoToControl To set the focus on the control you specify in the Control Name box. Under Comment, in the third cell, enter Activates the Address1 field. In the Control Name box, enter [straddr1] To make the Address1 field active if no value is entered in the Address1 field. This will make it easier to enter data into the form. 6 Save the macro as mcrrequireaddress 7 Close the macro 8 Open frmretailer in Design view 9 On the Design tab, click Property Sheet Activate the Event tab From the Before Update list, select mcrrequireaddress To open the Property Sheet for the form. You ll attach the mcrrequireaddress macro to this form. This macro ensures that the Address1 field isn t left blank. (If necessary.) To attach the macro to an event of this form. To specify that this macro runs before the BeforeUpdate event occurs. 10 Update the form and close the Property Sheet 11 Switch to Form view Make sure that students start entering values from the Retailer Name field, as the Retailer ID field is an AutoNumber field. Click Enter the following values: Retailer Name: Real Spices City: New York Region: NY ZIP Code: 10028 First Name: Alice Last Name: James Phone: (632) 545-8270 Fax: (632) 545-9126 Rep: 16 Parent Co: 001 Pay Method: COD The New (blank) record button is on the navigation bar. To display a new blank record. You ll leave the address blank for now. Your form should match the one shown in Exhibit 4-2.

Advanced macros 4 7 12 Close the form A message box appears with the message from the Action Arguments section of the Action MsgBox. Click OK Click No 13 In the Address1 box, enter 120 Dale St To close the message box. Another message box appears with the message, You can t save this record at this time, and asks whether to close the database object. The focus shifts to the Address1 text box control. To complete the record by filling the Address1 field. The Address2 field is not part of the macro and may be left blank. Close the form

4 8 Access 2007: Advanced Explanation Creating a macro for entering data You can automate data entry in some fields to reduce the number of errors and time spent on data entry. To do this, either set default values for the relevant fields or use a macro. When the validation of data on a form involves several fields, using macros can provide more control over the data. For example, when you enter the values for the quantity and unit price fields of a product, you can use the macro s SetValue action to calculate and set the value of the total price field. The SetValue action sets the value of a field based on the value the user enters in another field. To create a macro that helps automate the data entry: 1 Create a new macro in Design view. 2 Display the Condition column and enter the relevant condition. 3 Set the first action of the cell as SetValue. This action sets the value of the specified control, if the condition is true. 4 Under Action Arguments, in the Item box, enter the name of the control whose value you need to set. 5 In the Expression box, enter the value you want to set in the control. 6 Save the macro with a relevant name. 7 Open the Property Sheet for the control to which you want to attach the macro. 8 On the Event tab, attach the macro to the control s LostFocus event. Do it! A-2: Creating a data-entry macro Here s how 1 Create a new macro in Design view 2 On the Design tab, click Show All Actions Here s why You ll create a macro for automating data entry in the Order Date and Pay Method fields. (In the Show/Hide field.) To make all actions available in the Actions list. 3 Click Conditions To display the Condition column. 4 In the first Condition cell, enter [dtmorddate] Is Null This condition is true if you leave the Order Date field blank. In the first Action cell, select SetValue Under Action Arguments, in the Item box, enter [dtmorddate] In the Expression box, enter Now() To set the value of Order Date to the system date if the Order Date field is left blank. The Now() function displays the system date in the specified field.

Advanced macros 4 9 5 In the second Condition cell, enter [lngordretailerid] In (0003,0004,0008) This condition is true if the value of the Retailer field is 0003, 0004, or 0008. If you re adding a condition for text data entry, each option inside the parentheses must be enclosed within double quotation marks. Tell students to be sure to enter the quotes. In the second Action cell, select SetValue In the Item box, enter [strordpmethcode] In the Expression box, enter PO 6 Save the macro as mcrordervalidation Close the macro 7 Open frmorder in Design view Right-click the dtmorddate text box control and choose Properties Click the Event tab From the On Lost Focus list, select mcrordervalidation 8 Click the lngordretailerid text box Under the Event tab, from the On Lost Focus list, select the macro mcrordervalidation 9 Switch to Form view To set the value of the Pay Method field to PO if the Retailer field is 0003, 0004, or 0008. To open the Property Sheet for the dtmorddate text box control. You ll attach the macro to this control. If necessary. This macro runs when you shift the focus away from the Order Date field. The properties window now displays the properties of this control. To attach the macro mcrordervalidation to the LostFocus event of the lngordretailerid text box.

4 10 Access 2007: Advanced 10 Create a new blank record Press t Press t In the Retailer field, enter 0003 Press t Press t Press t Enter 21 To move to the Order Date field and test the first action of the macro. To move to the Retailer field. The Order Date field now contains the system date and time. The Order ID field is also filled, as it is an AutoNumber field and appears only when one of the fields is filled. To test the second action of the macro. To move to the Pay Method field. The Pay Method field is automatically filled with PO. The second action of the macro is satisfied and executes the corresponding action. To move to the Notes field. This field is optional, and you won t fill this field. To move to the Taken By field. To fill the field. 11 Create a new blank record Press t Press t To move to the Order Date field. To move to the Retailer field. The Order Date field is filled with the system date. In the Retailer field, enter 0006 Press t To move to the Pay Method field. The Pay Method field isn t filled automatically. The macro doesn t execute in this case, because its second condition is false. Enter CC for Pay Method and 14 as Taken By 12 Update and close the form

Advanced macros 4 11 Topic B: Creating macros that require user input Explanation When you need to perform tasks that depend on user input, you can create macros that accept values from the user and display the result based on these values. For example, if you want to display the details of all of the orders placed between two dates, you can create a macro that accepts the two dates from the user and displays the result based on these dates. Creating user-input macros To create a user-decision macro, run a parameter query by using a new macro. A parameter query, when executed, accepts values from the user and presents data according to the specified values. To create a macro that runs a parameter query: 1 Create a macro in Design view. 2 In the first cell, from the Action list, select OpenQuery. This action opens the specified query. 3 Under Action Arguments, from the Query Name list, select the parameter query. 4 Save the macro with a relevant name. 5 Close the Macro window. 6 Add a command button to the form. 7 Attach the macro to the relevant action of the command button.

4 12 Access 2007: Advanced Do it! B-1: Creating a macro that runs a parameter query Here s how Here s why 1 Create a new macro 2 In the first Action cell, select OpenQuery 3 From the Query Name list, select qryproductquery To set the macro s action to open a query. To set the action of the macro to open this query. This query accepts a value for Product ID from the user and displays the Product ID with the Product Name and In Stock available. 4 Save the macro as mcrstockavailable Close the macro 5 Open frmorderitem in Design view Create a new button on the form Click Cancel 6 Open the command button s Property Sheet You ll attach the macro to a command button on this form. (Click Button on the Design tab, then drag a button shape in the open area on the form.) The Command Button Wizard appears. To close the Command Button Wizard. (If necessary.) You ll attach the macro to an action of the command button. 7 Activate the Format tab Edit the Caption box to read Stock Status 8 Activate the Event tab To attach the macro to an event of the command button. From the On Click list, select mcrstockavailable The macro runs when you click the command button. It accepts a value for Product ID from the user and displays the Product ID with the Product Name and In Stock available. 9 Close the Property Sheet 10 Switch to Form view You ll test the macro. 11 Click Stock Status The macro runs and displays the Enter Parameter Value dialog box. If there is time, students can experiment with other values for Product ID. In the lngproductid box, enter 1 Click OK To view the details for this Product ID. The macro finishes, and the query displays the Product ID, Product Name, and In Stock details for Product ID 1.

Advanced macros 4 13 12 Close the query window 13 Update and close the form

4 14 Access 2007: Advanced Topic C: Creating the AutoKeys and AutoExec macros Explanation AutoKeys and AutoExec are special types of macros. The AutoKeys macro assigns shortcut key combinations to a set of tasks. AutoExec runs whenever you open the database, and performs a specific action, such as opening a form or table. You can create only one AutoKeys and one AutoExec macro in each database. Creating AutoKeys macros You use the AutoKeys macro to do routine tasks, such as printing the daily sales report. The AutoKeys macro is a special type of macro group. A macro group consists of multiple macros that have a single name. In the AutoKeys macro, each macro in the macro group is assigned a shortcut key combination, and you can run a specific macro by pressing the shortcut key combination for that macro. To create an AutoKeys macro: 1 Create a macro in Design view. 2 In the Action column, enter the actions. 3 On the Design tab, click the Macro Names button to display the Macro Name column. 4 In the Macro Name column, enter a key combination, which is also the macro name. 5 Save the macro as AutoKeys and close it. 6 Press the required key combination to verify that the macro works.

Advanced macros 4 15 Do it! C-1: Creating an AutoKeys macro Here s how Here s why 1 Create a new macro You ll create an AutoKeys macro. You can execute an action in an AutoKeys macro by using the specified key combination. 2 In the first Action cell, select OpenForm From the Form Name list, select frmretailer From the Data Mode list, select Edit To set the first action of the macro to OpenForm, which opens the specified form. (Under Action Arguments.) To set the first action of the macro to open the frmretailer form. To open the frmretailer form in the Edit mode when you run the macro. 3 In the second Action cell, select OpenForm From the Form Name list, select frmorderitem From the Data Mode list, select Edit 4 On the Design tab, click Macro Names In the first Macro Name cell, enter ^A (In the Show/Hide group.) The Macro Name column appears. You can enter the key combinations for the actions in this column. (The ^ character maps to the Ctrl key.) This is the key combination for the macro s first action. You can execute the action of opening the frmretailer form by pressing Ctrl+A. In the second Macro Name cell, enter ^B To set the key combination for opening the form, frmorderitem. 5 Save the macro as AutoKeys To make the current macro an AutoKeys macro. You must use this name for Access to recognize it as the shortcut keys file. 6 Close the macro 7 Press c + A To open the frmretailer form, which is the first action of the AutoKeys macro. 8 Press c + B To open the frmorderitem form, which is the second action of the AutoKeys macro. Close the forms

4 16 Access 2007: Advanced Explanation Creating AutoExec macros You might want to open a form or display a welcome message when a user opens a database. You can create an AutoExec macro to execute such tasks. The AutoExec macro executes automatically each time you open the database. To create an AutoExec macro: 1 Create a macro in Design view. 2 In the Action column, enter the actions. 3 Under Action Arguments, specify the arguments. 4 Save or rename the macro as AutoExec. 5 Close the database. 6 Reopen the database. 7 Verify that the macro runs. Do it! C-2: Creating an AutoExec macro Here s how Here s why 1 Run the macro mcrmacro1 A message box with the message Welcome to Outlander Spices appears. Click OK 2 In the Navigation Pane, right-click mcrmacro1 and choose Rename To close the message box. (If necessary.) You ll make this macro an AutoExec macro. The AutoExec macro runs when you open the database. 3 Edit the name to read AutoExec To rename this macro as AutoExec. You must use this name for the macro to run automatically when you open the database. Click anywhere in the Database window To deselect the macro. 4 Close the database 5 Reopen the database The AutoExec macro runs and the message box with the message Welcome to Outlander Spices appears. 6 Click OK To close the message box. Close the database

Advanced macros 4 17 Topic D: Creating macros for data transfer Explanation You can import, export, or link database objects from one Access database to another by using macros. You can also import, export, or link data between Access and spreadsheet applications, such as Microsoft Excel. This helps you to import or export records without copying manually. Creating macros to import database objects To import, export, or link data between Access databases, you use the TransferDatabase action of macros, illustrated in the Macro window in Exhibit 4-3. To do this: 1 Create a new macro. 2 On the Design tab, click Show All Actions. 3 From the Action list, select the action TransferDatabase. 4 Under Action Arguments, from the Transfer Type list, select Import. 5 From the Database Type list, select Microsoft Access. 6 In the Database Name box, enter the full path of the database from which the object is to be imported. 7 From the Object Type list, select Table. 8 In the Source box, enter the name of the table to be imported. 9 In the Destination box, enter a name for the table to be imported. 10 From the Structure Only list, select the option No to import both structure and data. 11 Save and run the macro. Some components of the Access environment have been moved or arranged for the exhibit. It will look different on students computers. Exhibit 4-3: The Macro window with a TransferDatabase macro

4 18 Access 2007: Advanced Do it! D-1: Importing a database object by using a macro Here s how Here s why 1 Open Import Macro From the current unit folder. Open tbldept This table contains nine records. You ll import this table into another database. Close the database 2 Open Adv Macros Click OK To close the message box. Tell students not to select TransferSQLDatabase. 3 Create a new macro 4 Click Show All Actions 5 Select TransferDatabase As the first action 6 Under Action Arguments, in the Transfer Type box, verify that Import appears In the Database Type box, verify that Microsoft Access appears You ll create a macro to import a table from another database. To specify the action as importing from another database. To specify the type of database from which you re importing the database object. Help students find the path for the current unit folder. In the Database Name box, enter C:\Student Data\Unit_04\Import Macro.accdb (The specific path may be different on your machine.) To specify the path of the database from which you re importing the database object. In the Object Type box, verify that Table appears You ll import a table from the Import macro database. 7 In the Source box, enter tbldept To specify the name of the table you re importing. In the Destination box, enter tbldept In the Structure Only box, verify that No is selected To specify the name of the imported table in the destination database. You ll import both structure and data. The Macro window now resembles Exhibit 4-3. 8 Save the macro as mcrimporttable

Advanced macros 4 19 9 Run the macro Close the macro Observe the Navigation pane The list of tables now includes tbldept. 10 Open tbldept All the records in the tbldept table of the Import Macro database appear in this table. 11 Close the table

4 20 Access 2007: Advanced Explanation Creating macros to export data to a spreadsheet You use the TransferSpreadsheet action of macros to import, export, or link data between an Access database and a spreadsheet application such as Microsoft Excel. To do this: 1 Open the Macro window of a new macro. 2 From the Action list, select the action, TransferSpreadsheet. 3 Under the Action Arguments section from the Transfer Type list, select Export. 4 In the Table Name box, enter the name of the table to be exported. 5 In the File Name box, enter the full path of the spreadsheet. 6 From the Has Field Names list, select the option Yes to treat the field names in the table as column titles in the spreadsheet. 7 Save and run the macro. Do it! D-2: Exporting data to a spreadsheet by using a macro Here s how Here s why 1 Open tblorder Notice the number of records. You ll export this table to a spreadsheet. Close the table 2 Create a new macro 3 Click Show All Actions 4 From the Action list, select TransferSpreadsheet 5 Under Action Arguments, from the Transfer Type list, select Export In the Spreadsheet Type list, verify that Excel Workbook is selected In the Table Name box, enter tblorder You ll create a macro to export the data from a table in this database to a spreadsheet. To specify the action as exporting from the database. To specify the spreadsheet application to which the data is to be exported. To specify the table from which you want to export data. Help students find the path for the current unit folder. In the File Name box, enter C:\Student Data\Unit_04\Export Excel (Your exact path might be different.) To export data to the specified Excel file. If the named Excel file doesn t exist, a new Excel file is created automatically. From the Has Field Names list, select Yes To treat the field names of the source table as column titles in the spreadsheet.

Advanced macros 4 21 6 Save the macro as mcrexportspreadsheet 7 Run the macro Close the macro If Excel 2007 is not installed on students computers, then have them navigate to the student data folder using Windows Explorer and simply confirm the presence of Export Excel.XLSX. 8 Click Start and choose All Programs, Microsoft Office, Microsoft Office Excel 2007 To start Excel. 9 In Excel, open Export Excel From the current unit folder Observe the spreadsheet (You might need to widen the date column to see all of the values.) The sheet contains all the records in the tblorder table. 10 Close the file 11 Close Excel Close the database

4 22 Access 2007: Advanced Unit summary: Advanced macros Topic A Topic B Topic C Topic D In this topic, you used the Condition column in macros to ensure data is entered in a specified field. You also used the SetValue action in macros to automate data entry. In this topic, you created and ran macros that work on user input. You also learned how to create a macro that runs parameter query. In this topic, you created the AutoKeys macro that consists of multiple macros. You also created the AutoExec macro that executes automatically when the database opens. In this topic, you imported a table from another database by using macros. You also exported data from a table to a spreadsheet by using macros. Review questions 1 What is a data validation macro? A macro that performs an action only when the specified criteria is satisfied. 2 What are the columns in the Macro Design view when you re creating a data validation macro? Condition, Action, Arguments, and Comment 3 Which of the following macro actions is used to place the insertion point in the specified control on a form? A MoveInsertionPoint B GoToRecord C GoToControl D GotFocus 4 How do you guarantee that users will enter data in a form field? Create a macro that uses the Is Null operator as the condition, and alerts the user if the field is left blank. 5 Which of the following macros is used to perform an action based on information entered by a user? A Data-entry macro B Simple macro C Data validation macro D User-input macro 6 How many AutoKeys macros can be created in a database? One, but many keyboard shortcuts can be defined in it. 7 When does an AutoKeys macro run? When you press the appropriate key combination.

Advanced macros 4 23 8 When does an AutoExec macro run? When the database is opened. 9 Which macro action is used to import database objects from other applications? TransferDatabase 10 Which macro action is used to export database records to Excel? TransferSpreadsheet Independent practice activity 1 Open Practice Adv Macros. 2 Create a new macro to ensure that the user enters the phone number of the retailer in the frmretailer form. The macro should ensure that the user doesn t save the record if no value is entered in the Phone field. Save this macro as mcrrequirephone. (Hint: Use the Conditions button and specify the criterion in the Condition column and the condition on the strphone field.) 3 Attach the macro to the BeforeUpdate event of the frmretailer form. 4 Verify that the macro runs. (Hint: Switch to the Form view.) 5 Enter the value for the Phone field and update and close the form. 6 Create a new macro to view the query, qrypaymethod. (Hint: From the Action list, select OpenQuery.) 7 Save the macro as mcrpaymethod. 8 Create a command button in the frmorder form. Give View pay method as the caption and attach the mcrpaymethod macro to the Click event of the button. 9 Verify that the macro runs. (Hint: Switch to the Form view and click the View pay method button. Enter NET30 in the Enter Parameter Value dialog box.) Compare your results with Exhibit 4-4. 10 Close the query and update and close the form. 11 Create an AutoKeys macro, so that you re able to open the forms, frmretailer and frmorder, in the Edit mode by using the key combination of Ctrl+A and Ctrl+B. Save the macro as Autokeys. Close the macro. Test other key combinations. 12 Press Ctrl+A to verify that frmretailer form opens. 13 Create an AutoExec macro to open the frmintro form automatically when the database opens. Close the database. 14 Open the database again to verify that the macro runs. 15 Close the form. 16 Create a macro to export the tblretailer table to the Practice Export Excel file. Save the macro as mcrpracticeexcel. Run the macro and close the Macro window. 17 Open Practice Export Excel file and verify that the records are exported. 18 Create a macro to import the tblemployee table from the Practice Import Macro database. Save the macro as mcrpracticeimport. Run the macro and close the Macro window.

4 24 Access 2007: Advanced 19 Open the table, tblemployee, and verify that records are imported. Close the table. 20 Close the database. Exhibit 4-4: The query result after step 9

5-1 Unit 5 Importing, exporting, and linking Unit time: 90 minutes Complete this unit, and you ll know how to: A Import to a database from another Access database, from Excel, and from CSV files. B Export objects from an active database to another Access database. C Export and import XML documents. D Link objects from one database to another and update the links. E Export and import tables and queries to the Windows SharePoint Services site.

5-2 Access 2007: Advanced Topic A: Importing objects This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007: # Objective 1.1.3 Define tables in databases Decide whether data should be linked to or imported from external sources 3.5.1 Import data from a specific source Import Microsoft Excel data Import CSV data 3.5.3 Save and run import specifications Explanation Objective 1.1.3 Importing objects from another Access database The Import feature imports objects and data from other Access databases and other external sources, such as Excel workbooks. Importing versus linking You can import objects directly, or link to them. Importing objects is the equivalent of taking a snapshot of the data: the values are imported into the database in whatever state they are in at the time of the import, and stay the same until changed by a user. As an alternative, you can import by creating a link to a database or workbook. Then if the data in the source file changes, the data in Access can be updated automatically. When importing by linking, the source file must remain available so that Access can update from it. Importing from another database You can import tables, queries, forms, or reports from one Access database into another. To import objects from an Access database: 1 Open the database into which you want to import the object. 2 On the External Data tab, click Access. 3 In the Get External Data Access Database dialog box, click Browse, navigate to the database from which you want to import the objects, and click Open. 4 In the Get External Database Access Database dialog box, click OK. The Import Objects dialog box appears, as shown in Exhibit 5-1. 5 Activate the tab that contains the type of object you want to import. 6 Select the required object(s). 7 Activate other tabs and select other objects that you want. 8 Click OK to import the selected objects.

Exhibit 5-1: The Import Objects dialog box Importing, exporting, and linking 5-3

5-4 Access 2007: Advanced Do it! A-1: Importing multiple objects Here s how Here s why Objective 1.1.3 1 Open Import Objects (From the current unit folder.) This database currently contains only one table, tblproduct. You ll import multiple objects to this database from the Objects database. 2 Activate the External Data tab Click Access 3 Click Browse and navigate to the current unit folder (The Access button is in the Import group.) The Get External Data Access Database dialog box appears. In the File Open dialog box, select Objects and click Open Verify the Import option is selected Click OK (You ll import tables from this database file.) To return to the Get External Data dialog box. Instead of the Link option. The Import Objects dialog box opens. 4 Verify that the Tables tab is activated Select tblorder and tblretailer (Click both tables.) You ll import these tables to the Import Objects database. 5 Activate the Queries tab To display the available queries. 6 Select qryretailerquery You ll import this query into the Import Objects database. 7 Activate the Forms tab To display the available forms. 8 Select frmorder You ll import this form. 9 Click OK Observe the Get External Data Access Database window There s an option to save these steps in case you need to perform this same import again. 10 Click Close Do not save the import steps. 11 Observe the Navigation Pane The tables tblorder and tblretailer, the query qryretailerquery, and form frmorder appear.

Importing, exporting, and linking 5-5 Explanation Objective 3.5.1 Importing an object from a workbook When you import data from workbook applications, such as Microsoft Excel, the column headings in the workbook correspond to the field names in the Access table. So, you must ensure that the data in the workbook is in the required format. To import data from Excel: 1 Open the database into which the Excel worksheet is to be imported. 2 On the External Data tab, in the Import group, click Excel. 3 In the Get External Data Excel Spreadsheet dialog box, click Browse and navigate to the file you want to import. Select the file and click Open. 4 Select the import option and then click OK to close the Get External Data Excel Spreadsheet dialog box and open the Import Spreadsheet Wizard. 5 Follow the wizard s instructions to import the worksheet. Saving import specifications If a database object will be imported repeatedly, you can create a Saved Import. The Get External Data dialog box used during a standard import includes an option to Save import steps. By selecting this option, the specific steps of the import are saved as a specification that can be run again in the future by selecting it from a list.

5-6 Access 2007: Advanced Do it! A-2: Importing an object from Excel Objective 3.5.1 Here s how 1 Choose Start, Programs, Microsoft Office, Microsoft Office Excel 2007 Here s why To start Excel. 2 Open Import Excel (From the current unit folder.) To open the Excel workbook. The single worksheet contains data about product orders. You ll import this Excel file into the Access Import Objects database. Close Excel 3 Verify that the Import Objects database is open (In Access 2007.) You ll import the Import Excel file into this database. Make sure students click Excel in the Import group, not in the Export group. 4 On the External Data tab, click Excel (In the Import group.) The Get External Data Excel Spreadsheet dialog box opens. 5 Click Browse and navigate to the current unit folder To import an Excel file. Select Import Excel and click Open Verify that the option to Import the source data into a new table is selected 6 Click OK To open the Import Spreadsheet Wizard. The wizard shows a preview of the worksheet. Verify that Show Worksheets is selected 7 Click Next Verify that First Row Contains Column Headings is checked To specify that the first row of the Excel worksheet contains field names for the table. 8 Click Next You can specify information about each field by selecting it and changing the field options.

Importing, exporting, and linking 5-7 9 Click Next Select Choose my own primary key. You ll specify which column to use as the primary field. From the list, select lngitemid If necessary. 10 Click Next The Import to Table box contains the name tblorderitem. This is the name of the imported table in Access. 11 Click Finish 12 Check Save import steps You ll save the import specifications so that you can quickly and easily import this file again. Edit the Save as box to read Import Order Item table To name the saved import specifications. In the Description box, enter from Excel workbook Click Save Import 13 Open tblorderitem in Design view Switch to Datasheet view To save the import specifications and close the dialog box. The new table appears in the Navigation Pane. The primary key appears in the lngitemid field. To see the imported records. 14 Close tblorderitem

5-8 Access 2007: Advanced Explanation Objective 3.5.3 Saved import specifications Import steps that were saved as a specification can be run as often as necessary. On the External Data tab, in the Import group, click Saved Imports and select a specification from the Manage Data Tasks dialog box, shown in Exhibit 5-2. Exhibit 5-2: The Manage Data Tasks dialog box

Do it! A-3: Using a Saved Import specification Importing, exporting, and linking 5-9 Here s how Here s why Objective 3.5.3 1 Open Import Excel Start Excel, and open the workbook file from the current unit folder. Edit the first value in the sngitemquantity column to read 600 Update and close the workbook 2 Open tblorderitem In Access. Observe the value in the sngitemquantity field for the first record It still indicates that 100 ounces were ordered. Close the table 3 Click Saved Imports In the External Data tab. The Manage Data Tasks dialog box appears. Verify that Import Order Item table is selected This is the import specification that you saved in the previous activity. The Excel icon indicates that this import will be drawn from an Excel workbook. 4 Click Run To import the Excel workbook again. The Microsoft Office Access dialog box appears. Click Yes Click OK Click Close To overwrite the existing table. The Microsoft Office Access dialog box displays, stating that the object was imported successfully. To acknowledge. To close the Manage Data Tasks dialog box. 5 Open tblorderitem The table has been updated. The sngitemquantity field for the first record now reads 600. Close the table

5-10 Access 2007: Advanced Explanation Objective 3.5.1 Importing text files You can import data from text files if they are formatted in a way that allows Access to interpret the contents as records and fields. In text files, each row of text is equivalent to a record, and the contents of the line are equivalent to fields. Two file formats supported by Access for this purpose are fixed-width files and delimited files. In a fixed-width file, each line is divided into fields that are the same size on each line. In a delimited file, a character such as a comma or a semicolon separates the fields. A commonly used delimited file format is Comma-separated value, which uses the.csv extension. 1 05-02354 Malcom Pingault SH 2/14/2001 45000 2 04-28973 Shannon Lee AC 2/20/1998 76600 3 11-19831 Melinda McGregor AD 5/5/2001 30200 1,05-02354,Malcom,Pingault,SH,2/14/2001,45000 2,04-28973,Shannon,Lee,AC,2/20/1998,76600 3,11-19831,Melinda,McGregor,AD,5/5/2001,30200 Exhibit 5-3: Data rendered in fixed-width and in delimited format Do it! A-4: Importing a CSV file Objective 3.5.1 Tell students to click in the Import group and not the Export group. Here s how 1 On the External Data tab, in the Import group, click Text File 2 Click Browse and navigate to the current unit folder Select tblemployee and then click Open Verify that the option to import the source into a new table is selected Here s why You ll import a CSV file into this database. The Get External Data Text File dialog box appears. 3 Click OK To open the Import Text Wizard. The wizard shows a preview of the text file. Verify that Delimited is selected 4 Click Next Under Choose the delimiter that separates your fields, verify that Comma is selected

Importing, exporting, and linking 5-11 5 Check First Row Contains Field Names Access will use the names in the first row as field names, instead of treating the first row as a data record. Click Next Click Next 6 Select Choose my own primary key. You ll set the primary key for this table. Verify that lngempid is selected in the list Click Next 7 Edit the name to read tblemployee Click Finish Click Close To close the wizard and import the file. If there is time, have students format the curearnings field. 8 Open tblemployee The employee information from the text file appears as an Access table. Close the database

5-12 Access 2007: Advanced Topic B: Exporting objects This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007: # Objective 5.4.1 Export data from tables 5.4.2 Export data from queries 5.4.3 Save and run export specifications Explanation Objectives 5.4.1, 5.4.2 Exporting objects from an Access database You can export tables, queries, forms, reports, and other objects from one database to another. You can export only one object at a time. Here s how: 1 In the Navigation Pane, select the object that you want to export. 2 On the External Data tab, click More and choose Access Database. 3 In the Export Access Database dialog box, click Browse and navigate to the file where you want to export the object. Select the file and click Save. 4 Click OK to open the Export dialog box, as shown in Exhibit 5-4. 5 Under Export Tables, select the required option. You can select the Definition and Data option to export both the design and data of the object, or you can select the Definition Only option to export only the object s design. 6 Click OK to export the object. 7 Click Close to close the Export Access Database dialog box. Exhibit 5-4: The Export dialog box

Importing, exporting, and linking 5-13 Do it! B-1: Exporting an object Here s how Here s why 1 Open Objects Observe the tables in the Navigation Pane There are four tables in the database. The database doesn t contain the table tblproduct. You ll export tblproduct from another database to this database. Objective 5.4.1 Tell students to click More in the Export group, not in the Import group. Close the database 2 Open Import Objects 3 In the Navigation Pane, select tblproduct 4 Activate the External Data tab Click More and choose Access Database 5 Click Browse and navigate to the current unit folder You ll export this table to another database. (In the Export group.) To open the Export Access Database dialog box. 6 Select Objects and click Save You ll export the table, tblproduct, to the Objects database. 7 Click OK To open the Export dialog box. In the Export tblproduct to box, the name of the table appears. Under Export Tables, verify that Definition and Data is selected Click OK You ll export the entire table, including its definition (or design) and data. To close the Export dialog box. 8 Click Close To close the Export Access Database dialog box. Close the database 9 Open Objects You ll verify that the tblproduct table was exported to this database. Observe the Navigation Pane The table tblproduct is now there. 10 Select qryretailerquery In the Navigation Pane.

5-14 Access 2007: Advanced Objective 5.4.2 Tell students to click Excel in the Export group, not in the Import group. 11 In the Export group, click Excel (In the Export group.) You ll export a query as an Excel workbook. Verify that the File name box displays the current unit folder and qryretailerquery.xlsx as the file name Verify that the file format box reads Excel Workbook (*.xlsx) Click OK To export the query. 12 Check Save export steps You ll save the export specifications so that you can quickly and easily export this query again. Edit the Save as box to read Export list of retailers In the Description box, enter Excel 2007 workbook Click Save Export To close the dialog box.

Importing, exporting, and linking 5-15 Explanation Objective 5.4.3 Saved export specifications As with imports, export steps can also be saved as a specification that can be run as often as necessary. On the External Data tab, in the Export group, click Saved Exports and select a specification from the Manage Data Tasks dialog box. Do it! B-2: Using a Saved Export specification Here s how Here s why Objective 5.4.3 1 Open tblretailer You ll update the retailer data, and export it from the retailer query. In the second record, under Address 2, enter Suite 20B Close the table 2 Click Saved Exports In the External Data tab. The Manage Data Tasks dialog box appears. The Saved Exports tab is activated by default. Verify that Export list of retailers is selected This is the export specification that you saved in the previous activity. The Excel icon indicates the export will be saved as an Excel workbook. 3 Click Run To export the query again. The Microsoft Office Access dialog box appears. Click Yes Click OK Click Close 4 Open the Excel workbook qryretailer Observe the second record To overwrite the existing workbook file. The Microsoft Office Access dialog box displays, stating that the query was successfully exported. To acknowledge the prompt. To close the Manage Data Tasks dialog box. (From the current unit folder.) In Excel 2007. (This is row 3 in the worksheet.) The address data you added is included in this workbook. Close the workbook Close Excel To return to Access 2007.

5-16 Access 2007: Advanced Topic C: Interacting with XML documents This topic covers the following Microsoft Certified Application Specialist exam objective for Access 2007: # Objective 5.5 Save database objects as other file types Save as an XPS file Extensible Markup Language (XML) Explanation The language used to construct a Web page is known as Hypertext Markup Language (HTML). HTML contains predefined tags that help construct a Web page. A tag is a command that specifies how a Web page should be formatted. For example, the Title tag in HTML is used to specify a title for the Web page. Extensible Markup Language (XML) is an extension of HTML a flexible text format designed for creating Web pages. It s flexible because designers can create their own customized tags, which isn t possible in HTML. However, users other than designers find it difficult to modify the Web page, as the tags are user-defined. To avoid this, designers need to specify how the data inside the tag appears on the Web page. This can be done by means of a style sheet. A style sheet is a file that defines the layout of a document, such as background color or font styles. The style sheet helps other users understand the format in which data is presented so that they can make necessary changes. The language commonly used to construct a style sheet is referred as Extensible Style Language (XSL). Such files have an.xsl extension. Because of its flexibility, you can use XML to transfer data easily between applications that have different formats for storing and structuring data. For example, you can use XML to share data between Access and Microsoft SQL Server. Exporting an Access object as an XML document You can export an Access object as an XML document so that other applications can access it. You can export an object in the following ways. Data (XML) To export both the structure and data of the object. For example, you can export a table with its data and the structure. This option creates a document with the extension.xml. Schema of the data (XSD) To export only the structure of the object. This option creates a document with the extension.xsd. Presentation of your data (XSL) To export the data of the object with its formatting styles. This option creates two documents with the extensions.htm and.xsl. However, this option is available only if the Data (XML) option is selected.

Importing, exporting, and linking 5-17 To export an Access object as an XML document: 1 On the External Data tab, click More and choose XML File. 2 Enter the name and location of the destination file. 3 Click OK to open the Export XML dialog box, shown in Exhibit 5-5. 4 In the dialog box, select the desired options. 5 Click OK to export. 6 Click Close to close the Export XML dialog box. Exhibit 5-5: The Export XML dialog box Importing an XML document You can import XML documents to the active database. You can import both the structure and the data, but you have to import the entire document, not just part of it. To import an Access object as an XML document: 1 Open the required database. 2 On the External Data tab, click XML File in the Get External Data group. 3 Click Browse, navigate to the desired file, click Open and then click OK. The Import XML dialog box opens, as shown in Exhibit 5-6. 4 Select the desired options and click OK. 5 Close the Get External Data XML File dialog box. Exhibit 5-6: The Import XML dialog box

5-18 Access 2007: Advanced Do it! C-1: Exporting and importing XML documents Here s how Here s why 1 Verify that Objects is open Tell students to click More in the Export group, not in the Import group. Open tblorderitem Close tblorderitem 2 On the External Data tab, click More and choose XML File 3 Verify that the File name box specifies the file tblorderitem.xml in the current unit folder This table contains 63 records. You ll export this table as an XML document. To open the Export XML File dialog box. Access provides a default name in the same folder as the original database. The current unit folder was the last folder used, and tblorderitem table is selected in the Navigation Pane. 4 Click OK To open the Export XML dialog box. By default, the options Data (XML) and Schema of the data (XSD) are selected. You ll export both the structure (or schema) and the data. 5 Click OK To export the table. The Export XML File dialog box appears. 6 Click Close To close the dialog box. 7 Close the database 8 Open Link Objects You ll import the XSD document, which stores the structure of the table, into this database. 9 On the External Data tab, click (In the Import group.) To open the Get External Data XML File dialog box. 10 Click Browse and navigate to the current unit folder If extensions are hidden for known file types, the file extension can be determined from the tool tip that displays when students point to a file, or by listing the files in Details view and observing the Type column. File icons and tool tips might look different on the students machines. Point to the second of the two files named tblorderitem Select tblorderitem Click Open A tool tip appears, identifying this as the XSD file. Select the XSD file, not the XML file. You ll import only the structure of the tblorderitem table.

Importing, exporting, and linking 5-19 11 Click OK To open the Import XML dialog box, as shown in Exhibit 5-6. 12 Click OK To close the dialog box. Click Close The Navigation Pane now displays the tblorderitem. 13 Open tblorderitem Only the table s structure is created. Close the table Select the tblorderitem table, press d and click Yes To delete tblorderitem. 14 Click XML File (On the External Data tab, in the Import group.) You will import the XML document, which stores both the structure and data. 15 Browse to tblorderitem and click Open Click OK Select XML file, not the XSD file. To open the Import XML dialog box. 16 Click OK Click Close The tblorderitem table now appears in the Database window. 17 Open tblorderitem Both the table s structure and its data are imported. The table contains 63 records. Close the table Close the database

5-20 Access 2007: Advanced Explanation Exporting with an XSL file In Access, you can export a database object with its data and structure, as well as the format of the data. When you export a database object with its format, Access automatically creates an XSL file and an HTML file of the database object. The XSL file describes how the data is rendered in the HTML document from the XML document. To export an Access object as an XML document with its XSL file: 1 In the Navigation Pane, select the table to be exported. 2 On the External Data tab, click More and choose XML File. 3 Choose the name and location of the exported file. 4 In the Export XML dialog box, select all three options. 5 Click OK. 6 Click Close.

Importing, exporting, and linking 5-21 Do it! C-2: Exporting to an XML document with an XSL file Here s how Here s why 1 Open Objects You ll export a table as an XML document with its XSL file. 2 Select tblorder In the Navigation Pane. Tell students to click More in the Export group, not in the Import group. 3 On the External Data tab, click More and choose XML File 4 Click Browse and navigate to the current unit folder In the File name box, verify that tblorder appears Click Save To open the Export XML file dialog box. 5 Click OK To open the Export XML dialog box. By default, the Data (XML) and Schema of the data (XSD) options are selected. 6 Check Presentation of your Data (XSL) To export the document with its XSL file. 7 Click OK To close the Export XML dialog box and to export the table. 8 Click Close To close the Export XML File dialog box. 9 Choose Start, My Computer To open the Windows Explorer window. Navigate to the current unit folder In addition to the tblorder.xml and tblorder.xsd files, there are two more tblorder files: tblorder.html and tblorder.xsl. These two files were created because you checked Presentation of your data (XSL). Help students identify the tblorder.xml file. 10 Double-click tblorder, as shown (The XML file.) The file opens in Internet Explorer. The Information Bar dialog box appears. Click Close Observe the file in the browser To close the dialog box. Only raw data displays. Close the browser

5-22 Access 2007: Advanced Help students identify the tblorder.htm file. 11 Double-click tblorder.htm, as shown The file opens in Internet Explorer and the Information Bar dialog box displays. Click OK 12 Click the Information Bar and choose Allow Blocked Content Click Yes Observe the file To close the dialog box. The Security Warning dialog box appears. To allow the blocked content. The exported HTML document displays in Web page form. It displays both the table and the data inside it. Close the browser Help students identify the tblorder.xsl file. 13 Open tblorder.xsl (Double-click the file, and close the Information Bar dialog box.) To see the XSL file for the table in the HTML form. Close the browser Close Windows Explorer

Importing, exporting, and linking 5-23 Saving an Access object to an XPS file Explanation Objective 5.5 You can save many Access objects as static documents. A static document is one that can be read by a user but not changed. Microsoft s XML Paper Specification (XPS) is one example of a static document format. Saving to a static document offers two advantages for sharing files with others: Users who receive an XPS file do not need to have Access installed to read it. An XPS file is a snapshot of the original Access object and cannot be altered. The author can be certain that no one can change the document content before passing it on. To save an Access object as a static document: 1 Click the Office button, and point to Save As. 2 Choose PDF or XPS. The Publish as PDF or XPS dialog box appears. 3 Edit the file name if necessary. 4 In the Save as type list, select PDF (*.pdf) or Microsoft XPS (*.xps). 5 Click Publish. Exhibit 5-7: The XML Paper Specification Viewer, displaying an XPS file

5-24 Access 2007: Advanced Do it! C-3: Saving to an XPS file Here s how Here s why Objective 5.5 The Microsoft Save as PDF or XPS Add-in for 2007 Microsoft Office programs must be installed to complete this activity. If students are running Windows XP, the XML Paper Specifications Pack is also required. 1 Select tblpaymethod You ll save the table in a format that can be viewed but not altered by users. Click Point to Save As Choose PDF or XPS (The Office Button is in the top left corner of the application window.) The File menu opens. To open the Save the current database object menu. The Publish as PDF or XPS dialog box opens. 2 In the Save as type box, select XPS Document (.xps) (If necessary.) The document will be saved in Microsoft s XML Paper Specification format. Navigate to the current unit folder Check Open file after publishing (If necessary.) 3 Click Publish To save the document in the.xps file format. The XML Paper Specification Viewer opens, displaying a printed version of the tbldept table. 4 Close the viewer Close the database

Topic D: Linking Access objects Importing, exporting, and linking 5-25 This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007: # Objective 1.1.3 Define tables in databases Decide whether data should be linked to or imported from external sources 3.5.2 Link to external data sources Link to Excel spreadsheets 6.2.6 Reset or refresh table links using the Linked Table Manager Explanation Objective 1.1.3 Creating object dependencies When you import an object into a database, only a copy of the imported object is placed into the imported database. If you make any changes to the data in the original object, these changes aren t reflected in the copy. If you want the changes to be reflected in both the object and the copy, you need to link the object instead of importing it. When you link objects, changes made in either are reflected in both. If the link is between two Access databases, you can link only tables. If the link is between an Access database and an external source, such as Microsoft Excel, you can link various objects. Linking a table To link a table: 1 Open the database on which you want to create the link. 2 On the External Data tab, click Access. Select Link to the data source by creating a linked table. 3 Enter or Browse to the database with which you want to establish the link. 4 Click OK to open the Link Tables dialog box. This dialog box lists the tables available in the selected database. 5 Select the table for which you want to create the link and click OK. 6 Click Close.

5-26 Access 2007: Advanced Do it! D-1: Linking to an Access table Here s how Here s why 1 Open Import Objects 2 On the External Data tab, click Access (On the Import tab.) The Get External Data Access Database dialog box appears. 3 Click Browse and select Links (From the current unit folder.) You ll create a link with a table in this database. Click Open 4 Select the Link option in the Get External Data dialog box. 5 Click OK To open the Link Tables dialog box, which lists the tables available in the selected database. There s only one table in this database. 6 Select tblpaymethod You ll create a link to this table in the Import Objects database. 7 Click OK To create the link. Observe the Navigation Pane The tblpaymethod table now appears in the list of tables. The arrow beside tblpaymethod indicates that it s a linked table. Close the database 8 Open Link Objects You also want to link this database with the Links database. 9 Click Access On the External Data tab. 10 Browse to the Links database and click Open To open the Link Table dialog box. You ll create a link to the table, tblpaymethod. 11 Select the link option and then click OK 12 In the dialog box, select the table tblpaymethod and click OK 13 Open tblpaymethod in Datasheet view You ll edit this table.

Importing, exporting, and linking 5-27 14 Select the third record and press d Click Yes To delete the third record. A message box appears giving the warning that you are about to delete one record. To close the message box and delete the record. Close the table Close the database 15 Open Links To verify whether the change is reflected in the source table. Open tblpaymethod The third record is deleted from this table also. Close the table Close the database 16 Open Import Objects Open tblpaymethod The third record is deleted from this table as well. Close the table Close the database

5-28 Access 2007: Advanced Explanation Objective 6.2.6 Using the Linked Table Manager You use the Linked Table Manager to view and update the location of all of the linked objects. For example, if you change the location of the source, you can update the link by using the Linked Table Manager. To do so: 1 Open the database in which you created the link. 2 On the Database Tools tab, click Linked Table Manager to open the Linked Table Manager dialog box, as shown in Exhibit 5-8. 3 Check the link that you want to update. 4 Click OK to open the Select New Location dialog box, which appears only if the link to the existing location is missing. 5 Navigate to the new location and select the table. 6 Click Open to display a message box indicating that the link is refreshed. 7 Click OK to return to the Linked Table Manager dialog box. 8 Update any other links, if necessary, and click Close to close the dialog box. Tell students that the path shown in the screen shot might differ from their own path. Exhibit 5-8: The Linked Table Manager dialog box Do it! D-2: Updating the links Here s how Here s why Objective 6.2.6 1 Open Windows Explorer Choose Start, All Programs, Accessories, Windows Explorer. 2 Navigate to the current unit folder Help students move the database. 3 Select Links in the current unit folder, and cut and paste it into the Archive folder Close Windows Explorer 4 Open Import Objects (You re moving it down one folder level.) To move the Links database to the Archive folder. You ll update the link with this new location.

Importing, exporting, and linking 5-29 5 Open tblpaymethod A message box appears indicating that the Links database could not be found. Click OK 6 On the Database Tools tab, click Linked Table Manager (In the Database Tools group.) To open the Linked Table Manager dialog box, which displays the link for the tblpaymethod table along with the location of the source. 7 Check tblpaymethod To update the link to reflect the new location. Click OK To open the Select New Location of tblpaymethod dialog box. 8 Navigate to the Archive folder To specify the new location. Select Links Click Open Click OK A message box appears indicating that the link has been refreshed. To close the message box. 9 Click Close To close the Linked Table Manager dialog box. 10 Open tblpaymethod To verify that the link is updated. Close the table Close the database 11 Open Link Objects Update the link to the table tblpaymethod Use the same procedure as you did above to update the link in Import Objects. 12 Open tblpaymethod To verify that the link is updated. Close the table

5-30 Access 2007: Advanced Explanation Objective 3.5.2 Creating links to Excel If you create a link between a database object and an Excel workbook, the link is only one-way. Changes made to the Excel workbook are reflected in the database, but linked database objects, such as tables, are read-only. You cannot make a change to the linked database table and have it update the Excel workbook. Linking a workbook To link a workbook: 1 Open the database on which you want to create the link. 2 On the External Data tab, click Excel. 3 Enter or Browse to the workbook with which you want to establish the link and click Open. 4 Select Link to the data source by creating a linked table, and click OK. 5 If the workbook includes column headings, check First Row Contains Column Headings, and click Next. 6 Enter a name for the table to be created and click Finish. A dialog box appears. 7 Click OK to acknowledge the prompt. Do it! D-3: Linking to an Excel workbook Objective 3.5.2 Tell students to click Excel in the Import group, not the Export group. Here s how 1 On the External Data tab, click Excel 2 Click Browse and select the Excel workbook tbldept Click Open 3 Select the Link option Here s why In the Import group. (In the current unit folder.) You ll create a link to this workbook. The Get External Data Excel Spreadsheet dialog box appears. 4 Click OK To open the Link Spreadsheet Wizard. 5 Check First Row Contains Column Headings Access will use the names in the first row as field names, instead of treating the first row as a data record. Click Next

Importing, exporting, and linking 5-31 6 Verify that the Linked Table Name field reads tbldept Click Finish Click OK This will be the name of the table in Access. The Link Spreadsheet Wizard dialog box appears. To acknowledge the prompt. The wizard closes. Observe the Navigation Pane The tbldept table now appears in the list of tables. The arrow indicates a linked table. The icon indicates the link is to an Excel workbook. 7 Open tbldept Edit the first field in the first record to read FN Observe the Navigation bar Select a record and press d The field is not editable. The New (blank) record button is disabled. You cannot add records to this table. The record is not deleted. This table is readonly. 8 Close tbldept 9 Start Excel Choose Start, Programs, Microsoft Office, Microsoft Office Excel 2007. Open tbldept In the SH row, edit the lngdeptmgr value to read 37 The Excel workbook. To change the number for the department manager. Update and close the workbook 10 Close Excel 11 Open tbldept (In Access.) The lngdeptmgr value for the SH record has changed to 37. Close the table Close the database

5-32 Access 2007: Advanced Topic E: Working with Windows SharePoint Services Explanation Windows SharePoint Services is a site where team members can share documents and exchange information about their projects. A SharePoint Services site can be a: Regular site A site that s published in a specific domain. Meeting Workspace site A site that helps you conduct online meetings with team members and track the attendees, agenda, and decisions made in the meetings. Document Workspace site A site that helps you share documents and information, such as tasks assigned to team members and their deadlines. The team members can post the required documents onto the SharePoint Services site, and other team members can access those documents through a Web browser. For example, you can post an Access table to this site, and any team member can access this table and make necessary changes through a Web browser. One advantage of this process is that the person making the changes doesn t need to know the Access application to work with the table. This is possible because the document opens in a browser, and changes are directly made on it. In Access, you post database objects by exporting them to the site. Later, you import these objects to update the changes made. List is the basic structure of the SharePoint Services site where data is presented in a tabular format, resembling an Access table. As you re posting all the necessary information to a centralized location, you can use the Windows SharePoint Services site as a database server while working with Access. Exporting tables to the SharePoint Services site To export tables and queries to lists on the Windows SharePoint services site, use the SharePoint List option in the Export Data group on the External Data tab. You must specify the name of the site to which you are exporting the tables and queries. By default, the name of the table or query appears as the list name. You can also specify another name for the table or query. The Export SharePoint Site dialog box is shown in Exhibit 5-9. To export a table to lists on the Windows SharePoint Services site: 1 Open the database and select the table to be exported. 2 On the External Data tab, in the Export group, click SharePoint List. 3 Specify the name of the SharePoint Services site. 4 In the List Name box, specify a different name for the table, if necessary. 5 In the Description box, type a description for the table, if necessary. 6 Check Open the list when finished to open the list after exporting the table. 7 Click OK to export the table.

Importing, exporting, and linking 5-33 Tell students that the name of the site might differ. Exhibit 5-9: The Export SharePoint Site dialog box Importing tables from the SharePoint Services site You can import a table that has been updated by another person from the Windows SharePoint Services site. To do this, you use the SharePoint List option on the External Data tab. To import tables from lists on the Windows SharePoint Services site: 1 Open the database to which the table is to be imported. 2 On the External Data tab, in the Import group, click SharePoint List. 3 In the Specify a SharePoint site box, enter the name of the SharePoint Service site and click OK. 4 Under Lists, select the required lists and follow the wizard s instructions to import the table.

5-34 Access 2007: Advanced Do it! E-1: Discussing Windows SharePoint Services Questions and answers 1 What is Windows SharePoint Services? A site where team members can share documents and exchange information about their projects. 2 What is a list in Windows SharePoint Services? The basic structure of the SharePoint Services site where data is presented in a tabular format, resembling an Access table. 3 Which wizard is used to export tables and queries to the Windows SharePoint Services site? Export to Windows SharePoint Services Wizard 4 What types of database objects can you export to the Windows SharePoint Services site? Tables and queries 5 Which wizard is used to import lists from the Windows SharePoint Services site? Import from Windows SharePoint Services Wizard

Importing, exporting, and linking 5-35 Unit summary: Importing, exporting, and linking Topic A Topic B Topic C Topic D Topic E In this topic, you imported an Access object to a database. You also imported multiple objects from another Access database into the currently active database. In addition, you imported an Excel worksheet and a CSV file as tables to an Access database. You also created a Saved Import specification. In this topic, you exported an object from one database to another. You also used a Saved Export specification. In this topic, you exported and imported Access objects as XML documents with their data and structure. You also exported Access objects as XML documents with their XSL file. Finally, you saved an object as an XPS file. In this topic, you learned how to link to an object in another database. You also learned how to update the link by using the Linked Table Manager. Finally, you learned how to link to an Excel workbook. In this topic, you learned how to export tables to the Windows SharePoint Services site. You also learned how to import tables as lists from the Windows SharePoint Services site. Review questions 1 How do you import objects from one Access database into another? On the External Data tab, click the Access button. 2 How do you export objects from one Access database into another? On the External Data tab, click More and choose Access Database. 3 What is the difference between the XML and HTML languages? XML is considered to be more flexible because designers can create their own customized tags. 4 Which XML component defines the layout of a document? A Style sheet B Tag C HTML D Web page setup 5 If you export only the structure of a database object as an XML document, you are exporting the. Schema 6 You can import a section of an XML document or the entire document. True or false? False. You have to import the entire document.

5-36 Access 2007: Advanced 7 If both linking and importing involve copying data between databases, how are they different? Linking objects creates dependencies so any changes made to one object will be reflected in the other. 8 What is the advantage of exporting Access tables and queries to a Windows SharePoint Services site? Team members can access and modify an Access table or query by using a Web browser and do not need to know how to use the Access application. Independent practice activity 1 Open Practice Import Objects. 2 Import the following objects from the Practice Objects database. (Hint: In the Import dialog box, from the Files of type list, select Microsoft Office Access.) The tblemployee table The qrydeptquery query The frmemployee form 3 From the Practice Import Objects database, export the tblretailer table to the Practice Objects database. Export both definition and data. 4 Close Practice Import Objects. 5 Open Practice Objects to verify that the table was successfully exported. 6 Export tblemployee table from Practice Objects as XML documents with its XSL file. Export it to the current unit folder. 7 Verify whether the table is exported with all the files. (Hint: Open Windows Explorer and, in the current unit folder, check whether there are files with the extensions.xml,.xsl,.xsd, and.htm. If necessary you can right-click on each file to determine its file extension.) 8 Link the Practice Objects database with the tbldept table in the Practice Links database. 9 Move the Practice Links database to the Archive folder. Verify whether the tbldept table in Practice Objects database can be opened. 10 Update the link. Now verify whether the tbldept table can be opened. 11 Close the table. 12 Close the database and the Windows Explorer window.

6 1 Unit 6 Database management Unit time: 45 minutes Complete this unit, and you ll know how to: A Work with database utilities to optimize resources. B Protect a database with a password and encryption. C Set Access options and database properties.

6 2 Access 2007: Advanced Topic A: Optimizing resources This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007. # Objective 1.4 Split databases To overcome size restrictions For multi-user applications 6.1.2 Back up databases 6.1.3 Compact and repair databases 6.1.4 Save databases as a previous version Database maintenance Explanation When many users access the same database, it s essential that the data is accessible and that resources and performance are optimized. The following can help: Converting databases To make data available in a different file format. For example, if you re working in Access 2000 and need to access data from a database created in Access 2007, you need to convert the Access 2007 database to Access 2000. Any features specific to the newer version of Access are lost when you convert the database to the older version. Analyzing database performance To improve the performance of a database. You can analyze the database by using Performance Analyzer, which displays a report containing suggestions for improvement. Splitting databases To increase the speed of data access in a network. You can split a database into two parts, one containing tables and the other containing objects, such as queries, forms, reports, macros, and modules. Splitting the database helps users customize their forms, reports, and other objects, while maintaining a single data source on the network. Compacting and repairing databases To reduce the size of the database and to repair it if it gets corrupted. The Compact and Repair utility does this. Backing up the database To save a copy of the database in a different location. For this, you use the Back Up Database option in the File menu. Converting databases Objective 6.1.4 In Access 2007, you can convert databases to and from any of the following formats: Access 2000 Access 2002-2003 Access 2007

Database management 6 3 Remember that if you save a file in an older format, any features specific to the newer format will be lost. You don t need to convert older databases to the newer format you can work with them as they are, but earlier versions of Access can t open a 2007-format file. Earlier versions of Access saved databases with the extension mdb. Access 2007 uses the extension accdb. To save a database in a different file format: 1 Open the database in Access 2007. 2 Click the Office Button, then click the arrow to the right of Save As. 3 In the Save as dialog box, navigate to the desired folder. 4 Enter a file name. 5 Click Save. Access actually copies and converts. After saving a database to a different file format, the converted file will be opened in Access, but the original file will still be available as it was before the conversion. Do it! A-1: Converting a database to a prior version Here s how Here s why Objective 6.1.4 Tell students that Access 2007 supports the 2000 and newer file formats. 1 Open Manage DB (From the current unit folder.) You ll convert this Access 2007 database to an Access 2002-2003 file format so that an Access 2003 user can use it. 2 Click The Office Button is in the top left corner of the application window. 3 Point to the arrow to the right of Save As Choose Access 2002-2003 Database Navigate to the current unit folder To open the Save the database in another format menu. The Save As dialog box appears. If necessary. Edit the File name box to read Manage DB 2003 4 Click Save To convert the database. Observe the title bar The file is in Access 2002-2003 format. 5 Close Manage DB 2003 Observe the Open Recent Database Pane (On the Getting Started screen.) Both formats of the file are listed.

6 4 Access 2007: Advanced Analyzing database performance Explanation The Performance Analyzer, as shown in Exhibit 6-1, examines the performance of one or all of the objects in a database and displays suggestions for improvement. To use the Performance Analyzer, open the database you want to analyze and click Analyze Performance on the Database Tools tab. Exhibit 6-1: The Performance Analyzer dialog box When you run the Performance Analyzer, it generates a report that suggests improvements in the design of the selected database object. The report might recommend ways of changing the data type of a field, compiling an application, or editing the syntax in a procedure. The report, an example of which is shown in Exhibit 6-2, consists of the following sections: Analysis Results The analysis result for the selected objects. The result of the analysis can be a recommendation, a suggestion, or an idea. If you want to implement the recommendation or suggestion, select it and then click Optimize. The Performance Analyzer implements it and marks it as fixed. However, you must implement the ideas yourself. Key States the meaning of the icons in the Analysis Results list. Analysis Notes Explains the item selected in the Analysis Results list.

Exhibit 6-2: An analysis report generated by the Performance Analyzer Database management 6 5

6 6 Access 2007: Advanced Do it! A-2: Analyzing performance Here s how Here s why 1 Open Optimize DB 2 On the Database Tools tab, click Relationships (In the Show/Hide group.) To open the Relationships window. The window shows the relationship between the tables. Notice that there s no direct relationship between the tables tblorder and tblproduct. Close the Relationships window 3 Click (In the Analyze group on the Database Tools tab.) To open the Performance Analyzer dialog box. It contains tabs for various database objects. 4 Activate the All Object Types tab Click Select All Click OK To view all of the database objects. You ll analyze all the objects in the database. To start the analysis. A progress bar appears indicating the progress of the analysis. After the analysis, the Performance Analyzer dialog box appears, as shown in Exhibit 6-2. Tell students that they can select the suggestion or recommendation and then click the Optimize button to implement it. 5 Observe the dialog box The Analysis Results list displays the objects, which you can modify to increase the database performance. It also provides advice on how to optimize each object. The Key section gives the levels of advice regarding performance. Each line in the Analysis Results list displays one of the icons in the Key section. The Analysis Notes section provides more information on the selected item. 6 From the Analysis Results, select the suggestion Table tblproduct : Relate to table tblorder Tell the students to click OK if a warning message appears. Click Optimize You ll implement this suggestion. The Optimize button activates. This option, if implemented, relates the tables tblproduct and tblorder. The suggestion icon is changed to a fixed icon. This means that Access has implemented the suggestion.

Database management 6 7 7 Click Close To close the Performance Analyzer dialog box. 8 Display the Relationships window (Click Relationships on the Database Tools tab.) There is now a relationship between the tables, tblorder and tblproduct. This was implemented automatically by Access. Close the Relationships window Close the database

6 8 Access 2007: Advanced Explanation Objective 1.4 Splitting databases If multiple users access the same database simultaneously, or if a database grows excessively large, the speed of data access might decrease. You can improve performance by splitting the database into back-end and front-end databases or by having multiple copies of the database. When you split a database, the back-end database contains the tables, whereas the frontend database contains user interface objects, such as forms, reports, and links to the tables in the back-end database. You can place the back-end database on a centralized network computer and put copies of the front-end database on each user s computer. So, when a user creates forms or reports in the front-end database, it won t affect the speed of data retrieval in the back-end database. Splitting a database this way ensures that all users are updating the same database. In the case of a large database, splitting the database allows separate computers processors to manage the tasks of operating the front and back end, thereby increasing the speed of data access. To split a database: 1 Open the database you want to split. 2 On the Database Tools tab, click Access Database. 3 Click Split Database to open the Create Back-end Database dialog box. 4 Specify the name of the back-end database and click Split to start the splitting process. Do it! A-3: Splitting a database Here s how Here s why Objective 1.4 1 Open Split DB 2 On the Database Tools tab, click Access Database (In the Move Data group.) To open the Database Splitter wizard. 3 Click Split Database To open the Create Back-end Database dialog box. Access suggests the name, Split DB_be.accdb, for the back-end database. This back end database is created in the current unit folder after the database is split. Tell students to click Open if a Security Notice displays. 4 Click Split To start the splitting process. The status bar indicates that the tables are being exported to the back-end database. After the tables are exported, the Database Splitter dialog box informs you that the database has been split successfully. Click OK Observe the Navigation Pane To close the Database Splitter dialog box. The Database Splitter Wizard also closes. The pointer to the left of each table name indicates that the tables in the present database are linked to the tables in another database.

Database management 6 9 5 Observe the Queries section of the Navigation Pane Observe the Forms section The database contains two queries. The database contains two forms. Close Split DB Tell students that this database is to be stored in the centralized computer. 6 Open Split DB_be This is the back-end database for the application. It contains only tables. The frontend database contains the rest of the database objects. Open tblorder This table contains 25 records. Close tblorder 7 Observe the Queries section of the Navigation Pane Observe the Forms section of the Navigation pane There are no queries. Queries for this split database are contained in the front-end database, Split DB. There are no forms. 8 Close the database 9 Open Split DB You ll add a record to the table, tblorder, through the form frmorder. Open frmorder 10 Create a new record Click New (blank) record in the navigation bar. In the Order Date field, enter 8/3/2006 From the Retailer list, select Spice World All the other fields are filled automatically. Update and close the form Close the database 11 Open Split DB_be Tell students that the Retailer column contains the corresponding retailer ID, and the Taken By column contains the corresponding employee ID. Open tblorder Close tblorder Close the database The record you entered appears in the last row. The names of the retailer and of the employee who took the order are represented by their respective IDs.

6 10 Access 2007: Advanced Explanation Objective 6.1.3 Compacting and repairing databases As you create, modify, or delete various database objects over time, your database may become fragmented. Fragmentation is the scattering of data in the database across empty spaces on the hard disk, increasing the size of the database. To fix this problem, you can compact a database by using the Compact and Repair Database utility. This utility arranges all the objects contiguously on the hard disk, so that they take up less space. You can also use this utility to repair a database if it gets corrupted due to a power failure or virus attack. The compact and repair features have been integrated into a single option. To start to repair or compact a database, open the database and click the Office Button. Then point to Manage and choose Compact and Repair Database. Do it! A-4: Using the Compact and Repair Database utility Here s how Here s why Objective 6.1.3 Tell students not to open Manage DB 2003. 1 Open Manage DB You ll compact this database. 2 Click Point to Manage Choose Database Properties To open the Manage this database menu. To open the Manage DB.accdb Properties dialog box. 3 Activate the General tab (If necessary.) To view the size of the database. Observe the Size Click Cancel 4 Open the Manage this database menu This is the size of the file before being compacted. To close the dialog box. Click the Office Button and point to Manage. Choose Compact and Repair Database 5 Open the Manage DB Properties dialog box Observe the Size Click OK (Click the Microsoft Office Button, point to Manage, and choose Database Properties.) The size of the file is smaller after being compacted. To close the Manage DB Properties dialog box.

Database management 6 11 Explanation Objective 6.1.2 Backing up databases To prevent loss of data due to virus attack, accidental deletion, or equipment failure, you should make a backup copy of your database and save it to another location. To back up a database. 1 Open the database. 2 Click the Office Button. 3 Point to Manage and choose Back Up Database from the Manage this database menu. The Save As dialog box appears. 4 Enter a name for the backup database. By default, the backup name is the current name followed by the date. 5 Click Save to create a copy of the database. Do it! A-5: Backing up a database Objective 6.1.2 Ask students to take note of the objects in this database. Here s how 1 Verify that the Manage DB database is open 2 Open the Manage this database menu Choose Back Up Database Observe the backup file name. Here s why You ll make a backup copy of this database. Click the Office Button and point to Manage. To open the Save As dialog box. It s the current file name plus today s date. 3 Click Save To close the Save As dialog box and to save the backup copy of the database. The status bar first shows the progress of backing up and then displays Ready. 4 Close Manage DB 5 Open the backup you just made 6 Observe the Navigation Pane The database backup contains the same tables and forms as in the Manage DB database. 7 Close the database

6 12 Access 2007: Advanced Topic B: Protecting databases This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007. # Objective 6.1.1 Open databases Exclusively 6.2.1 Encrypt databases using passwords Explanation Objective 6.2.1 Objective 6.1.1 Encrypting with a password Setting a password for a database a simple way to secure it and prevent unauthorized users from accessing it. Authorized users can log on to the database and access all the objects in it by using the password. It s best to set a password when only a few reliable users need to access the database. In Access 2007, setting a password also encrypts the database. This prevents users from accessing the database through other programs, such as word processors or other database programs. Encryption is the process of converting an object, such as a database, to an unreadable format in order to secure data from unauthorized users. Even if some unauthorized users gain access to the database, the data they see is undecipherable. To assign a password and encrypt a database, open the database in exclusive mode. When you do this, other users cannot read or modify the database. To encrypt and password-protect a database: 1 Click the Office Button and choose Open. 2 In the Open dialog box, navigate to the required folder and select the database. 3 From the Open list, select Open Exclusive to open the database in exclusive mode so that you can set the password. 4 On the Advanced Tools tab, click Encrypt with Password to open the Set Database Password dialog box. 5 In the Password box, enter a password. Re-enter the password in the Verify box and click OK. 6 Close the database and reopen it to verify that the password is set.

Do it! B-1: Encrypting a database with a password Database management 6 13 Here s how 1 Click the Office Button and choose Open Here s why To display the Open dialog box. Tell students to select the database and not double-click it. Objective 6.1.1 2 Select Security DB (In the current unit folder.) Don t double-click it. You ll open this database to set a password. Click the down arrow next to the Open button, as shown To view the options in the Open list. Objective 6.2.1 More information on passwords in Access, such as maximum length and allowable characters, can be found by searching Help for Create password. Select Open Exclusive 3 On the Database Tools tab, click Encrypt with Password In the Password box, enter secure In the Verify box, enter secure Click OK To open the database in exclusive mode. When setting a password, open the database in exclusive mode so that other users cannot modify it. To open the Set Database Password dialog box. To set this as the password for the database. The password appears as a set of asterisks. To confirm the password. To set the password and close the Set Database Password dialog box. 4 Close the database You ll reopen the database to verify that the password is set. Open the database 5 In the Enter database password box, enter secure Click OK The Password Required dialog box appears. To specify the password. The database opens. Close the database

6 14 Access 2007: Advanced Explanation Removing password protection and encryption To remove a password from a database and unencrypt it: 1 Open the database in exclusive mode by using the password. 2 On the Database Tools tab, click Decrypt Database to open the Unset Database Password dialog box. 3 Enter the password for the database and click OK. 4 Close the database and reopen it to verify that the password is removed. Do it! B-2: Removing a password and encryption Here s how 1 Open Security DB in exclusive mode Enter secure Click OK 2 On the Database Tools tab, click Decrypt Database In the Password box, enter secure Click OK Here s why (Click the Office Button. Choose Open, select Security DB and then choose Open Exclusive from the Open list.) The Password Required dialog box appears. This is the current database password. You ll remove the password from this database. To close the dialog box and open the database. To open the Unset Database Password dialog box. Access requires you to know the password to unset it. To remove the password and close the dialog box. 3 Observe the Database Tools tab The title of the button has changed from Decrypt Database to Encrypt with Password, because the database is now decrypted. Close the database You ll reopen the database to verify that the password has been removed. 4 Open Security DB The database opens without prompting for a password.

Topic C: Setting options and properties Database management 6 15 This topic covers the following Microsoft Certified Application Specialist exam objectives for Access 2007. # Objective 6.2.2 Configure database options Enable error checking Show/Hide navigation pane Set up startup display form 6.2.3 Set database properties Populate a property Create a custom property Explanation Objective 6.2.2 Access Options and database properties You can use Access Options and database properties to customize Access and individual databases. Access Options You can customize your Access experience by changing the settings in Access Options. For example, you can set options that hide the Navigation Pane and launch a specific form whenever the database opens. This can be useful if your database will be opened by users who are not very tech-savvy, and you want them to open only specific database objects, such as forms or reports. You can also use Access Options to enable or disable different levels of error checking in a database.

6 16 Access 2007: Advanced To change Access Options: 1 Open a database. 2 Click the Office Button and choose Access Options. 3 Select, clear, or enter options as needed, as shown in Exhibit 6-3. 4 Click OK to close the Access Options dialog box and save the changes. Exhibit 6-3: The Current Database pane in the Access Options dialog box Some changes to Access Options require you to close and reopen the current database. In this case, Access prompts you to close and reopen the database.

Database management 6 17 Do it! C-1: Setting Access Options Here s how Here s why 1 Click To display the File menu. You ll set options that make this database better suited for casual users. Objective 6.2.2 Objective 6.2.2 Click Access Options 2 In the left pane, select Current Database 3 Under Application Options, in the Display Form list, select Startup display form 4 Under Navigation, clear Display Navigation Pane 5 In the left pane, select Object Designers Under Error checking, observe the error checking options Clear Enable error checking In the lower-right corner of the menu. The Access Options dialog box appears. If necessary. You ll make changes that affect only Security DB. To automatically display this form when the database opens. To hide the Navigation Pane when this database opens. By default, error checking is enabled in Access 2007. You do not need to enable error checking for each new database. All of the specific error checks beneath this option are now disabled. Objective 6.2.2 Select Enable error checking All of the error checks become active. 6 Click OK To close the Access Options dialog box and save the changes. The Microsoft Office Access dialog box appears, stating that you must close and reopen the database. Click OK To acknowledge the prompt. Close and reopen Security DB 7 Observe the database The Navigation Pane is no longer available in this database. The Startup display form appears, providing buttons for users to navigate and open only specific database objects. 8 In the Forms group, click Order Form The Order form opens. Close the form

6 18 Access 2007: Advanced Explanation Objective 6.2.3 Database properties Database properties are metadata that are attached to the database file. Metadata is data about other data. Database properties include information that define the file. This may include information regarding the file s author, owner, users, and significant dates in its creation and use. Access provides preconfigured database properties that you can populate with information. You can also create custom database properties to hold information. To populate an existing property: 1 Open the database. 2 Click the Office Button and choose Manage, Database Properties. 3 Use the tabs to navigate the properties dialog box. 4 Enter information in the boxes provided. 5 Click OK to close the dialog box and save the changes. To create a custom property: 1 Open the Properties dialog box. 2 Activate the Custom tab. 3 Select a custom property from the list, or enter a new custom property in the Name box. 4 In the Type list, select the type of data to be stored for this property. 5 Enter the new property s information in the Value box. 6 Click Add, as shown in Exhibit 6-4. 7 Click OK. Exhibit 6-4: The Custom tab in the Properties dialog box

Do it! C-2: Creating and populating properties Database management 6 19 Here s how Here s why 1 Click To display the File menu. 2 Choose Manage, Database Properties The Security DB.accdb Properties dialog box appears. You ll populate a property of this database file and create a custom property. 3 Activate the Summary tab If necessary. In the Author box, enter your own name This is the equivalent of signing your work. Users who have to update and maintain this database in the future will now know whom to contact with questions. 4 Activate the Custom tab You ll create and populate a custom property. 5 In the Name list, select Owner Owner appears in the Name box. You ll create a property that identifies the individual who requested and therefore owns this database file. In the Type list, verify that Text is selected You ll store text in this property. Objective 6.2.3 In the Value field, enter Jake Andrews Objective 6.2.3 Click Add 6 In the Name box, enter Launch Date In the Type list, select Date In the Value box, enter a date two months from now, in the format mm/dd/yyyy Click Add To populate this custom property. You ll create a custom property that is not provided in the list. To enter the date. To create and populate this custom property. 7 Click OK To close the dialog box and save the properties. Close the database

6 20 Access 2007: Advanced Unit summary: Database management Topic A Topic B Topic C In this topic, you converted a database to a previous version of Access. You also learned how to analyze the performance of the database and split the database into back-end and front-end databases. You also learned how to compact and repair a database. Then, you learned to make a backup of a database. In this topic, you set a password for a database which also secured the database with encryption. You then removed the password and unencrypted the database. You learned that you should open the database in exclusive mode to set or remove a password and encryption. In this topic, you configured Access Options for a database. Then, you populated database file properties and created custom properties. Review questions 1 Which of the following activities is done specifically to increase the speed of data access across a network? A Using the Performance Analyzer B Converting the database C Compacting the database D Splitting the database 2 Which utility is used to reduce the size of a database and repair it when it becomes corrupted? Compact and Repair utility 3 When opening a database that was created with a previous version of Access, what is the effect of converting it to Access 2007 file format? After converting the database, it cannot be opened in any prior versions. 4 What might cause a database to become corrupted? A power failure or a virus 5 How do databases become fragmented? Why is this a problem? As you create, modify, and delete database objects, over time the data is scattered across the hard disk. Fragmentation can increase the size of the database and decrease the overall database performance. 6 What is the procedure to password-protect and encrypt a database? a Click the Office Button, choose Open, and navigate to the database you want to protect. b c d e From the Open list, select Open Exclusive. On the Database Tools tab, click Encrypt with Password. Enter a password and re-enter it to confirm it. Click OK and close the database.

Database management 6 21 7 Who can remove the password and encryption from a database? Anyone who knows the current password can remove it. 8 What safeguard does encryption provide? It converts the database into undecipherable code. Independent practice activity 1 Open Practice Manage DB. 2 Convert this database to the Access 2000 version. Save the converted database as Practice Manage 2000 in the current unit folder. 3 Open Practice Replica DB. Analyze the performance of all the objects in the database. Implement the suggestion in the database and verify that the suggestion is implemented. Close the database. 4 Open Practice Split DB. 5 Split the database and save the back-end database as Practice Split DB_be. Close the database. 6 Open Practice Manage DB. Check the size of the database. Compact the database. Verify whether the size of the database is reduced after compacting. 7 Add a password to the database. (Hint: Close the database and re-open it in exclusive mode.) 8 Close and reopen the database to verify that the password is set. 9 Remove the password. Close and reopen the database to verify that the password has been removed. 10 Close the database.

6 22 Access 2007: Advanced

7 1 Unit 7 Internet integration Unit time: 30 minutes Complete this unit, and you ll know how to: A Create and modify hyperlink fields. B Collect data via e-mail.

7 2 Access 2007: Advanced Topic A: Hyperlink fields Explanation Access provides a hyperlink data type to store links to e-mail addresses, Web sites, documents on your computer, or other objects in the database. Hyperlinks in Access databases When you click a link in a hyperlink field, the site, e-mail address, or document opens in its associated program. For instance, if you click a stored e-mail address, the default mail program will start and create a new message with that address in the To field. You can also store links to documents such as Microsoft Word files; clicking this kind of link will cause the document to open in Word. To create a hyperlink field: 1 Open the desired table in Design view. 2 Add a blank field. 3 In the Field Name column, enter a name for the field. 4 In the same row, from the Data Type list, select Hyperlink to set the data type for the field. 5 In the Description column, enter a description for the field, if desired. Do it! A-1: Creating a hyperlink field Here s how Here s why 1 Open Data From the current unit folder. 2 Open tblretailer in Design view You ll modify the design of this table by adding a hyperlink field in which retailer e-mail addresses will be stored. 3 Under Field Name, place the insertion point in the strphone cell Right-click and choose Insert Rows To insert a new field in the table. 4 Type hle-mail To name the new field. From the Data Type list for the E-mail field, select Hyperlink Under Description, enter Retailer s e-mail address 5 On the General tab, in the Caption field, enter E-mail The Caption field determines the name of the column heading in Datasheet view. 6 Update the table

Internet integration 7 3 Inserting data in a hyperlink field Explanation To enter data in a hyperlink field, you can type a Web page or e-mail address in the specific column in Datasheet view of the table. You can also use the Insert Hyperlink dialog box. For an e-mail address, if you are typing the address in Datasheet view, you ll need to type mailto: before the e-mail address. If you use the Insert Hyperlink dialog box, mailto: automatically appears before the e-mail address, as shown in Exhibit 7-1. You can also use the Link to list in the Insert Hyperlink dialog box to insert links to Web pages or database objects. The Link to list permits you to select the type of link you need. The available options in this list are: Existing File or Web Page E-mail Address To insert data in a hyperlink field: 1 Open the table in Datasheet view. 2 Right-click in a hyperlink field and choose Hyperlink, Edit Hyperlink. You can also put the insertion point in the field and press Ctrl-K. 3 Under Link to, select the type of hyperlink you want to create. 4 Enter an e-mail address for the hyperlink, or browse to a target file. 5 Click Screen Tip to add screen tip text. 6 Click OK to close the dialog box. The hyperlink appears in the cell. The contents of the Recently used e-mail addresses list might vary based on previous use of this dialog box. Exhibit 7-1: The Insert Hyperlink dialog box