access2007 m2

34
http://pds.hccfl.edu/pds Microsoft Access 2007 Module 2

Upload: jigeno

Post on 14-Feb-2017

571 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Access2007 m2

http://pds.hccfl.edu/pds

Microsoft Access 2007Module 2

Page 2: Access2007 m2
Page 3: Access2007 m2

©2007 Hillsborough Community College - Professional Development and Web Services

Microsoft Access 2007:Module 2

August 2007

Page 4: Access2007 m2

The material contained in this training material is copyrighted ©2007 Hillsborough Community College Department of Professional Development and Web Services and may not be reproduced without express, written permission. Other trademarks, trade names, logos, designs, brand names, and product services mentioned in this publica-tion may be trademarks or registered trademarks of third parties.

Hillsborough Community College - Professional Development and Web Services

Page 5: Access2007 m2

Table of Contents

i

Microsoft Access 2007 - Module II

Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1

Import a Table from Excel . . . . . . . . . . . . . . . . . . . . . . . . . . .3

Export an Access Table to Excel . . . . . . . . . . . . . . . . . . . . . . .5

Create a Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6

Query

Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8

Show . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

Text Data Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Field Not in Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Comparison And . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Comparison Or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Avg (Average) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Parameters and the Between Operator . . . . . . . . . . . . . . . . . 21

Report Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Modify a Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Insert Images into a Form or Report . . . . . . . . . . . . . . . . . . . 26

Resize Images in a Form or Report . . . . . . . . . . . . . . . . . . . . 27

Page 6: Access2007 m2
Page 7: Access2007 m2

Microsoft Access 2007 - Module II

Objectives

At the end of this training session you will be able to:

1. Import a table from Excel;

2. Export an Access table to Excel;

3. Create a query;

4. Sort fields in a query;

5. Show fields in a query;

6. Run a query using wildcards;

7. Run a query for fields not in result;

8. Run a query for a number value;

9. Run a query using the comparison criteria “And”;

10. Run a query using the comparison criteria “Or”;

11. Understand the purpose of Aggregate Functions;

12. Create and run a query using count;

13. Create and run a query using average;

14. Create and run a query using the parameter between;

15. Insert and resize a graphic/image;

16. Create and Modify a Report.

Page 8: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

2

Page 9: Access2007 m2

Microsoft Access 2007 - Module II

Import a Table From Excel

Access and Excel work well together . It is quite simple to import data from an already existing Excel spreadsheet .

In this example, we are using the files located on your computer’s desktop, in the PDWS folder .

�. Open this module’s Access 2007 file.

e.g. Desktop > PDWS folder >Access > Access II > Access2007_M2.accdb

Under the External Data tab>Import group, click on Excel.

2. After the Get External Data dialog box appears, click on Import the source data into a new table in the current database.

Other options are to append the new records to a table or link the Excel spreadsheet to the Access database. If you choose to append the records to a table, make sure the fields and data types match with the existing data.

�. Click on the Browse button and select the file to import.

e.g. Desktop > PDWS folder >Access > Access II > Employee_Add.xlsx

4. Click OK.

5. Select which worksheet or range to import by clicking on the Show Worksheets or Show Named Ranges radio button.

e.g. Show Worksheets

6. Select the sheet or sheet range to import and click on Next.

e.g. Sheet1

7. Add a check mark by clicking on the First Row Contains Column Headings and click on Next. Adding this check mark specifies that the first row contains a column heading.

2

1

3

56

7

Page 10: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

4

8. You can specify information about the spreadsheet fields on this screen, such as data type. You can even specify if you do not want to import a certain field. These specifications are set in the Field Options area.

In this example, we are going to import all fields.

9. Click Next.

�0. Choose the appropriate primary key setting and click on Next.

In this example the ID is the primary key; however, Access can choose a primary key. Also you can choose a primary key or choose not to have any primary key.

Select Choose my own primary key and ID from the drop-down list.

��. Type a name for the table and click on Finish.

e.g. tblEmployeeAddresses

12. If you will be importing a file repeatedly, Access gives you an option to save the import steps. For this example, do not check to Save import steps and click on the Close button.

��. tblEmployeeAddresses now appears in the left pane, under Tables.

10

9

8

11

12

13

Page 11: Access2007 m2

5

Microsoft Access 2007 - Module II

Export an Access Table to Excel

Any database table can be exported, in a variety of formats . In this example, we are going to export to Excel .

�. In the Navigation Pane, select the object to export,

e.g. tblEmpInfo

2. In the External Data tab>Export group, select Excel.

�. Click the Browse button to select a destination for the exported file.

4. Select an appropriate file format. If you need to share this file with people that do not have Excel 2007, choose Microsoft Excel 97-2003. If that is not a concern, select Excel Workbook.

5. Specify the appropriate export options. Add a checkmark to Export data with formatting and layout. You can also select the option Open the destination file after the export operation is complete, if you would like to preview the exported file.

6. Click on OK.

7. If you elected to Open the destination file after the export operation is complete, Excel will open with the new exported file displayed.

8. Save the export steps, if this is a regularly occurring export and click Close.

4

2

3

1

56

7

8

Page 12: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

6

Create a Query

A query allows for table inquiries . A query can change, delete, add, and arrange data in tables . Queries also aid gathering information for forms and reports . With a query you can ask questions and set parameters .

�. Select the Create tab.

2. In the Other group, select Query Wizard.

�. Select Simple Query Wizard and click OK.

4. Under Tables/Queries, click on the down arrow and select the tables and/or queries to create and run a new query.

e.g. tblEmpInfo.

5. In the Available Fields list, select the table's field(s) to add to the query.

In this example, all the fields are used; therefore, click on the double-headed arrow icon to move all the items (fields) to the Selected Fields list.

6. Click Next.

21

3

4

5

6

Page 13: Access2007 m2

7

Microsoft Access 2007 - Module II

7. Select a Detail or Summary.

e.g. Detail

8. Click on Next.

9. Type a title for the query, such as qryEmployeeComp.

�0. Click on either the Open the query to view information radio button or the Modify the query design radio button.

e.g. Modify the query design

��. Click Finish.

�2. The qryEmployeeComp query is now displayed in Design View.

7

8

9

1011

12

Page 14: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

8

Query in Design View: Sort

Sorting information can be a valuable tool when dealing with large amounts of information or when simply organizing information (fields). More than one field can be sorted; however, the field farthest to the left is given priority when sorting .

Fields can be sorted by: Ascending Descending Not Sorted

In this example, the LastName field is sorted in ascending order .

�. While in Design View, click in the blank box next to Sort, under Lastname; a down arrow appears.

2. Select the sort option.

e.g. Ascending

�. In the Query Tools/Design tab>Results group, click the Run button to activate the query and see your results.

4. Go back to Design View to edit your query.

2

3

1

4

Page 15: Access2007 m2

9

Microsoft Access 2007 - Module II

Query in Design View: Show

The Show option displays or hides fields in a query or form .

In this example, some fields will be hidden.

�. While in Design View, uncheck the show box for Exempt, Zip Code and Street.

To show fields in a query’s results, add a check to each field name’s Show checkbox . To hide fields in a query’s results, remove the check in the field name’s Show checkbox .

2. Click the Run button to see your query results. Notice that the Exempt, Zip Code and Street fields are not being shown.

�. Select Design View to make more adjustments to the query design.

1

2

3

Page 16: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

�0

Query: Text Data Criteria

Text Data is data in fields that are in text format . Such examples include but are not limited to names, addresses, employee number, location, etc .

In this example, employees that are exempt are queried .

�. In the Criteria section under Exempt, type the text data criteria.

e.g. Yes

2. Check the Show box for Exempt, to show this field in the results.

�. In the Query Tools/Design tab>Results group, click the Run button.

4. The results of the query now display all employees that are Exempt.

12

Run a query looking for employees who live in Temple Terrace. How many HCC employees live in Temple Terrace?

Activity

3

4

Page 17: Access2007 m2

��

Microsoft Access 2007 - Module II

Query Criteria: Wildcards

In this example, the last name of an em-ployee with the letter M is queried .

�. Go back to Design View. In the Criteria section under LastName, type the text data criteria.

e.g. M*

2. Click on the Run button.

�. The results of a query now display all employees with a last name that begins with the letter M.

Wildcards are useful in Access to serve as a character or blending of characters . There are two types of wildcards in Access * (asterisk) ? (question mark) The * wildcard symbolizes any compilation of characters . Therefore, mi* stands for the letters mi, followed by any letter combination . The ? wildcard symbolizes any defined letter. As a result, B?rt operates as the letter, B, followed by any single letter, r, and t . Appropriately, B?rt can mean Bert or Burt .

1

2

Run a query looking for employees working at a cam-pus with the letter D. How many employees work at a campus with the letter D?

How would you run a query for employees working at District? How many employees work at District?

Activity

3

Page 18: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

�2

Query Criteria: Field Not in Result

Field Not in Result is a query where criteria for a specific field do not need to appear in the outcome of the final query. In this example, the last name, first name, and middle initial are necessary . However, the campus does not need to appear . Therefore, a query with only the names of the employees working at the Brandon campus is required .

�. In Design View, uncheck the items to be hidden.

e.g. Campus

2. Type criterion in the Criteria section, under Campus.

e.g. BR

�. Click on the Run button.

4. The results of the query now display all employees at the Brandon campus.

12

3

4

Page 19: Access2007 m2

��

Microsoft Access 2007 - Module II

Query Criteria: Number

Using a number in a criteria is useful when information from a data field that consists of numbers is required . A dollar sign or decimal point is not required in the criterion .

In this example, the names, campuses, and the salary of employees earning $39,800 .00 are needed .

�. In Design View, type criterion in the Criteria section. For example, under Salary, type 39800. Do not type in the dollar sign or the decimal point. Uncheck unnecessary fields, such as Street, City, State, ZipCode and Exempt.

2. Click on the Run button.

�. The results of the query now display all employees whose salary is $�9,800.00.

1

Run a query looking for employees earning $60,000. How many employees are earning $60,000?

Activity

3

2

Page 20: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

�4

Query Criteria: Comparison

Using a number in a criteria is useful when information from a data field that consists of numbers is required . A dollar sign or decimal point is not required in the criterion .

In this example, the names, campuses, and the salary of employees earning more than $30,000 .00 is needed .

�. In Design View, type criterion in the Criteria section.

e.g. Under Salary, type >30000. Do not type in the dollar sign or the decimal point.

2. Click on the Run button.

�. The results of the query now display all employees earning more than $�0,000.

1

Run a query looking for employees earning less than $�0000. How many employees are earning less than $�0,000?

Activity

3

2

Page 21: Access2007 m2

�5

Microsoft Access 2007 - Module II

Query Criteria: Comparison AND

Using the AND criteria is appropriate when information is needed from multiple fields. AND conditions must appear on the same criteria line, for example, the names of employees earning more than $30,000 .00 at the Dale Mabry campus .

�. In Design View, type criterion in the Criteria section.

e.g. Under Salary, type >30000. Do not type in the dollar sign or the decimal point.

2. Type the AND criterion.

e.g. Under Campus, type DM.

�. Click on the Run button.

4. The results of the query now display all employees earning more than $�0,000 at the Dale Mabry campus.

Since the two conditions are on the same line, each one must be true .

12

Run a query looking for employees working at the Ybor campus and who are exempt. How many em-ployees are working at the Ybor campus and are exempt?

Activity

4

3

Page 22: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

�6

Query Criteria: Comparison OR

Using the OR criteria is applicable when in-formation is needed from multiple fields.

OR conditions must appear on the separate lines .

In this example, the names of employees earning less than $30,000 .00 or with the last name beginning with the letter M are required .

�. Type criterion in the Criteria section.

Under Salary, type <30000. Do not type in the dollar sign or the decimal point.

2. Type the OR criterion.

Under Last Name, type M* on a separate line.

�. Click on the Run button.

4. The results of the query now display all employees earning less than $�0,000 or employees with a last name beginning with the letter M.

Since the two conditions are on separate lines, at least one condition must be true .

2 1

4

Run a query looking for employees working at the Ybor (YB) campus or the Plant City (PC) campus.

Activity

Page 23: Access2007 m2

�7

Microsoft Access 2007 - Module II

Aggregate Functions

Aggregate functions within Access allows the user to carry out simple mathematical operations within a query . Aggregate functions (operations) include sum, average, minimum, maximum, count, standard deviation and variance . These functions can be accessed by selecting the Totals button on the query design toolbar or typing the aggregate function in the Total row of the Design grid .

Aggregate Function Description

Sum Determines the sum of field values. Supports the following data types: AutoNumber, Currency, Date/Time and Number .

Avg Calculates the average of field values. Supports the following data types: AutoNumber, Currency, Date/Time and Number .

Min Determines the lowest field value. Supports the following data types: AutoNumber, Currency, Date/Time, Number and Text .

Max Determines the highest field value. Supports the following data types: AutoNumber, Currency, Date/Time and Number .

Count Determines the number of records in a field. Supports the following data types: AutoNumber, Currency, Date/Time, Memo, Number, OLE Object, Text and Yes/No .

StDev Calculates the standard deviation of a field value. Supports the following data types: Currency or Number .

Var Calculates the statistical variances of a field. Supports the following data type: Currency .

Page 24: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

�8

Query: Using the Aggregate Function Count

Using the aggregate function Count is useful when a simple count or tally of information is required .

�. In the Create tab>Other group, select Query Design.

2. Select the tables and/or queries to show and click Add.

e.g. tblEmpInfo

�. Click Close.

4. Double click on a field name from the table or query twice to appear in the query design grid.

e.g. Campus.

1

2

3

4

Page 25: Access2007 m2

�9

Microsoft Access 2007 - Module II

5. In the Query Tools/Design tab>Show/Hide group, click on the Totals button.

6. The Total row now appears in the design grid between Table and Sort.

7. Select the aggregate function on the second Campus field

e.g. Count.

8. Click on the Run button.

9. Result of query using the aggregate function Count.

�0. Save the query as qryCntCampus.

7

5

6

Create a query for gender using the aggregate func-tion Count. Save the query as qryCntGender

How many are males? How many are females?

How could using the aggregate function Count be useful to you?

Activity

8

9

Page 26: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

20

Query: Using the Aggregate Function Avg

Using the aggregate function Avg (average) is useful when an average of information is required .

In this example, we are determining the average salary by campus .

�. Under the Create tab>Other group, select Query Design.

2. Select the tables and/or queries to show and click Add.

e.g. tblEmpInfo

�. Click Close.

4. Double click on the field names from the table to appear in the Field design grid.

e.g. Campus and Salary.

5. Click on the Totals button. The Total row now appears in the design grid between Table and Sort.

6. Select the aggregate function on the second field

and click on the Run button.

e.g. Avg.

7. Result of query using the aggregate function Average.

8. Save the query as qryAvgSalaryCampus.

3

2

4

5

6

7Create a query for the average salary by city using the aggregate function Avg. Save the query as qryAvgSalaryCity.

Which city has the highest average salary?

How could using the aggregate function Avg be use-ful to you?

Activity

Page 27: Access2007 m2

2�

Microsoft Access 2007 - Module II

Query: Using Parameters and the Between Operator

Creating a parameter query allows you to search for information in fields. However, for the parameters to function, you will have to enter the criteria when prompted by the parameter dialog box .

In this example, we are determining the names of the people whose start date is between 1/01/1980 and 12/31/1999.

�. Under the Create tab>Other group, select Query Design.

2. Select the tables and/or queries to show and click Add.

e.g. tblEmpInfo

�. Click Close.

4. Double click on the field names from the table to appear in the Field design grid.

e.g. FirstName, LastName, and StartDate.

5. Under StartDate Criteria type the following: Between [Beginning Start Date] And [Ending Start Date].

1

2

3

4

5

Page 28: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

22

6. Click on the Run button and enter the following parameters Beginning Start Date: 1/01/1980 and Ending Start Date: 12/31/1999.

7. Result of query using the parameter Between.

8. Save the query as qryBtwnStartDate.

Create a query using parameters. The query will show the names of people, salary and campus. Save the query as qryBtwSalaryCampus.

Show how many people make between $�0,000 and $40,000 and at which campus he/she works.

What are the results for each campus?

Activity

6

7

8

Page 29: Access2007 m2

2�

Microsoft Access 2007 - Module II

Create a Report: Report Wizard

Report Wizard is easy to use and allows for the design, development, printing, and print preview of information such as labels, lists, form letters, invoices, summaries, display charts, etc . The user can personalize reports by adding a logo or picture, organizing headers, footers and sorting columns .

In this example, the names of employees earning more than $30,000 .00 or with the last name beginning with the letter M are required . Adjust the qryEmployeeComp query, if necessary .

�. In the All Access Objects pane, select the object that you would like to use for creating the report. For example, select qryEmployeeComp.

2. Under the Create tab>Reports group, select Report Wizard.

�. Make sure the correct table or query is selected. Add Available Fields to Selected Fields and click on Next.

In this example, qryEmployeeComp should be selected and add all available fields.

4. Add any grouping levels; however, in this example do not add any. Therefore, click on Next.

1

2

3

4

Page 30: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

24

5. Sort records, up to four fields in ascending or descending order, and click on Next. In this example, the fields LastName and FirstName, are sorted in ascending order.

6. Choose a report layout and orientation and click on Next.

e.g. Tabular layout and Landscape orientation

7. Choose a report style and click on Next.

e.g. Access 2007

8. Type in a report title, preview the report, or modify the report’s design and click on Finish.

e.g. rptEmployeeInfo

9. The Employee Information report now appears.

6

7

5

8

9

Page 31: Access2007 m2

25

Microsoft Access 2007 - Module II

Modify a Report

Design View and Layout View allow for the modification and customizing of reports by adding a logo or picture, organizing headers, footers, and sorting columns .

In this example, the Employee Information report is modified.

�. In the Home tab>Views group, select View > Design View to change to Design View.

2. The report now appears in Design View.

�. To change the font, highlight the text box, then make your font selection. For example, click on the Last Name label text box and choose a larger font size. Also change the alignment to Center.

4. Select Report View see the changes.

5. Report changes are viewable.

To move report objects around, click on an object and drag it to the new location, while you are in Design View or Layout View . You can also resize and delete columns .

Modify rptEmployeeInfo by changing the font, size and color. Change the report header title to HCC Employee Information. Delete unnecessary columns to save space.

Activity

1

3

4

5

Page 32: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

26

Insert a Graphic/Image

Personalize forms and reports by adding a company logo or another graphic . To insert a graphic into a form or report, you can be in Design View or Layout View . In this example, we’ll use Design View.

�. In the Report Design Tools/Design tab>Control group, click Image.

2. Take the image pointer and click and hold, then draw a rectangle to the approximate size of the graphic in the location where the image will appear. Release mouse button after the Image box is drawn.

In this example, the HCC logo is added to the report header.

�. After the Insert Picture dialog box appears, locate the file and click on OK.

e.g. Desktop > PDWS Folder > Access II> HCCLogo.

4. Resize graphic with sizing handles.

1

2

3

4

Page 33: Access2007 m2

27

Microsoft Access 2007 - Module II

Resize Image/Graphic

Sometimes after an image is placed on a form or report, it does not fit properly in its box . Below are the steps to resize an image without resizing the box entirely .

�. Select the image.

2. Right click on the mouse and click on Properties.

�. Click on the Format tab.

4. Point to and click on Size Mode down arrow and choose Stretch.

5. The image now fits in the box.

Insert an image into your report and resize the image using the Resize Image/Graphic steps.

Activity

1

2

3

4

5

Page 34: Access2007 m2

Hillsborough Community College - Professional Development and Web Services

28