Access2007_M2

download Access2007_M2

of 34

Transcript of Access2007_M2

  • 8/7/2019 Access2007_M2

    1/34

    http://pds.hcc.edu/pds

    Microsoft Access 2007

    Module 2

  • 8/7/2019 Access2007_M2

    2/34

  • 8/7/2019 Access2007_M2

    3/34

    2007 Hillsborough Community College - Professional Development and Web Services

    Microsoft Access 2007:

    Module 2

    August 2007

  • 8/7/2019 Access2007_M2

    4/34

    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

  • 8/7/2019 Access2007_M2

    5/34

    Table of Contents

    Microsoft Access 2007 - Module I

    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

  • 8/7/2019 Access2007_M2

    6/34

  • 8/7/2019 Access2007_M2

    7/34

    Microsoft Access 2007 - Module I

    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 elds in a query;

    5. Show elds in a query;

    6. Run a query using wildcards;7. Run a query for elds 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.

  • 8/7/2019 Access2007_M2

    8/34

    Hillsborough Community College - Professional Development and Web Services

    2

  • 8/7/2019 Access2007_M2

    9/34

    Microsoft Access 2007 - Module I

    Import a Table From Excel

    Access and Excel work well together It isquite simple to import data from an alreadyexisting Excel spreadsheet

    In this example, we are using the leslocated on your computers desktop, in thePDWS folder

    . Open this modules Access 2007 le.

    e.g. Desktop > PDWS folder >Access > Access

    II > Access2007_M2.accdb

    Under the External Datatab>Import group,

    click on Excel.

    2. After the Get External Data dialog boxappears, 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 elds and data types

    match with the existing data.

    . Click on the Browse button and select the le to

    import.e.g. Desktop > PDWS folder >Access > Access

    II > Employee_Add.xlsx

    4. ClickOK.

    5. Select which worksheet or range to import by

    clicking on the Show Worksheets orShow

    Named Ranges radio button.

    e.g. Show Worksheets

    6. Select the sheet or sheet range to import andclick 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 species that the rst

    row contains a column heading.

    2

    1

    3

    5

    6

    7

  • 8/7/2019 Access2007_M2

    10/34

    Hillsborough Community College - Professional Development and Web Services

    4

    8. You can specify information about the

    spreadsheet elds on this screen, such as data

    type. You can even specify if you do not want to

    import a certain eld. These specications are

    set in the Field Options area.

    In this example, we are going to import all

    elds.

    9. ClickNext.

    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 IDfrom the drop-down list.

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

    e.g. tblEmployeeAddresses

    12. If you will be importing a le 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, underTables.

    10

    9

    8

    11

    12

    13

  • 8/7/2019 Access2007_M2

    11/34 5

    Microsoft Access 2007 - Module I

    Export an Access Table toExcel

    Any database table can be exported, in avariety of formats In this example, we aregoing to export to Excel

    . In the Navigation Pane, select the object to

    export,

    e.g. tblEmpInfo

    2. In the External Datatab>Export group, select

    Excel.

    . Click the Browse button to select a destination

    for the exported le.

    4. Select an appropriate le format. If you need

    to share this le 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 le after the export

    operation is complete, if you would like to

    preview the exported le.

    6. Click on OK.

    7. If you elected to Open the destination le

    after the export operation is complete, Excel

    will open with the new exported le displayed.

    8. Save the export steps, if this is a regularly

    occurring export and clickClose.

    4

    2

    3

    1

    5

    6

    7

    8

  • 8/7/2019 Access2007_M2

    12/34

    Hillsborough Community College - Professional Development and Web Services

    6

    Create a Query

    A queryallows for table inquiries A query

    can change, delete, add, and arrange

    data in tables Queries also aid gathering

    information for forms and reports Witha 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 clickOK.

    4. UnderTables/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'seld(s) to add to the query.

    In this example, all the elds are used; therefore,

    click on the double-headed arrow icon to move

    all the items (elds) to the Selected Fields list.

    6. ClickNext.

    2

    1

    3

    4

    5

    6

  • 8/7/2019 Access2007_M2

    13/34

  • 8/7/2019 Access2007_M2

    14/34

    Hillsborough Community College - Professional Development and Web Services

    8

    Query in Design View: Sort

    Sorting information can be a valuabletool when dealing with large amounts ofinformation or when simply organizinginformation (elds). More than one eld can

    be sorted; however, the eld farthest to theleft is given priority when sorting

    Fields can be sorted by:AscendingDescendingNot Sorted

    In this example, the LastName eld is

    sorted in ascending order

    . While in Design View, click in the blank box

    next to Sort, underLastname; 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

  • 8/7/2019 Access2007_M2

    15/34 9

    Microsoft Access 2007 - Module I

    Query in Design View: Show

    The Show option displays or hides elds in

    a query or form

    In this example, some elds will be hidden.

    . While in Design View, uncheck the show box

    forExempt, Zip Code and Street.

    To show elds in a querys results, add acheck to each eld names Show checkboxTo hide elds in a querys results, removethe check in the eld names Showcheckbox

    2. Click the Run button to see your query results.

    Notice that the Exempt, Zip Code and Street

    elds are not being shown.

    . Select Design View to make more adjustments

    to the query design.

    1

    2

    3

  • 8/7/2019 Access2007_M2

    16/34

    Hillsborough Community College - Professional Development and Web Services

    0

    Query: Text Data Criteria

    Text Data is data in elds that are in text

    format Such examples include but are notlimited to names, addresses, employeenumber, location, etc

    In this example, employees that are exempt

    are queried

    . In the Criteria section underExempt, type the

    text data criteria.

    e.g. Yes

    2. Check the Show box forExempt, to show this

    eld 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.

    1

    2

    Run a query looking for employees who live in

    Temple Terrace. How many HCC employees live in

    Temple Terrace?

    Activity

    3

    4

  • 8/7/2019 Access2007_M2

    17/34

    Microsoft Access 2007 - Module I

    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 underLastName, 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 asa character or blending of characters

    There are two types of wildcards in Access* (asterisk)? (question mark)

    The * wildcard symbolizes any compilationof characters Therefore, mi* standsfor the letters mi, followed by any lettercombination

    The ? wildcard symbolizes any dened letter.

    As a result, B?rt operates as the letter,B, followed by any single letter, r, and tAppropriately, 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

  • 8/7/2019 Access2007_M2

    18/34

    Hillsborough Community College - Professional Development and Web Services

    2

    Query Criteria: Field Not inResult

    Field Not in Result is a query wherecriteria for a specic eld do not need to

    appear in the outcome of the nal query. Inthis example, the last name, rst name, andmiddle initial are necessary However, thecampus does not need to appear Therefore,a query with only the names of theemployees working at the Brandon campusis 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.

    1

    2

    3

    4

  • 8/7/2019 Access2007_M2

    19/34

    Microsoft Access 2007 - Module I

    Query Criteria: Number

    Using a number in a criteria is useful wheninformation from a data eld that consistsof numbers is required A dollar sign or

    decimal point is not required in the criterion

    In this example, the names, campuses, andthe salary of employees earning $39,80000are needed

    . In Design View, type criterion in the Criteria

    section. For example, underSalary, type 39800.

    Do not type in the dollar sign or the decimal

    point. Uncheck unnecessary elds, 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

  • 8/7/2019 Access2007_M2

    20/34

    Hillsborough Community College - Professional Development and Web Services

    4

    Query Criteria: Comparison

    Using a number in a criteria is useful wheninformation from a data eld that consistsof numbers is required A dollar sign ordecimal point is not required in the criterion

    In this example, the names, campuses, andthe salary of employees earning more than

    $30,00000 is needed

    . In Design View, type criterion in the Criteria

    section.

    e.g. UnderSalary, 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

  • 8/7/2019 Access2007_M2

    21/34 5

    Microsoft Access 2007 - Module I

    Query Criteria: ComparisonAND

    Using the AND criteria is appropriate wheninformation is needed from multiple elds.

    AND conditions must appear on the samecriteria line, for example, the names ofemployees earning more than $30,00000

    at the Dale Mabry campus

    . In Design View, type criterion in the Criteria

    section.

    e.g. UnderSalary, type >30000. Do not type in

    the dollar sign or the decimal point.

    2. Type the AND criterion.e.g. UnderCampus, 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

  • 8/7/2019 Access2007_M2

    22/34

    Hillsborough Community College - Professional Development and Web Services

    6

    Query Criteria:Comparison OR

    Using the ORcriteria is applicable when in-

    formation is needed from multiple elds.

    ORconditions must appear on the separate

    lines

    In this example, the names of employees

    earning less than $30,00000 or with the

    last name beginning with the letter M are

    required

    . Type criterion in the Criteria section.

    UnderSalary, type

  • 8/7/2019 Access2007_M2

    23/34 7

    Microsoft Access 2007 - Module I

    Aggregate Functions

    Aggregate functions within Access allowsthe user to carry out simple mathematicaloperations within a query Aggregatefunctions (operations) include sum,

    average, minimum, maximum, count,standard deviation and variance Thesefunctions can be accessed by selecting theTotals button on the query design toolbaror typing the aggregate function in the Totalrow of the Design grid

    Aggregate Function Description

    Sum Determines the sum of eld values. Supports thefollowing data types: AutoNumber, Currency, Date/

    Time and Number

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

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

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

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

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

    Number

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

  • 8/7/2019 Access2007_M2

    24/34

    Hillsborough Community College - Professional Development and Web Services

    8

    Query: Using the AggregateFunction Count

    Using the aggregate function Count isuseful when a simple count or tally ofinformation is required

    . In the Createtab>Other group, select Query

    Design.

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

    clickAdd.

    e.g. tblEmpInfo

    . ClickClose.

    4. Double click on a eld name from the table or

    query twice to appear in the query design grid.

    e.g. Campus.

    1

    2

    3

    4

  • 8/7/2019 Access2007_M2

    25/34 9

    Microsoft Access 2007 - Module I

    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 eld

    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

  • 8/7/2019 Access2007_M2

    26/34

    Hillsborough Community College - Professional Development and Web Services

    20

    Query: Using the AggregateFunction Avg

    Using the aggregate function Avg(average) is useful when an average ofinformation is required

    In this example, we are determining theaverage salary by campus

    . Under the Create tab>Other group, select

    Query Design.

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

    clickAdd.

    e.g. tblEmpInfo

    . ClickClose.4. Double click on the eld 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 eld

    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

  • 8/7/2019 Access2007_M2

    27/34 2

    Microsoft Access 2007 - Module I

    Query: Using Parameters and theBetween Operator

    Creating a parameter query allows you tosearch for information in elds. However, forthe parameters to function, you will have

    to enter the criteria when prompted by theparameter dialog box

    In this example, we are determining thenames of the people whose start date isbetween 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

    clickAdd.e.g. tblEmpInfo

    . ClickClose.

    4. Double click on the eld 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

  • 8/7/2019 Access2007_M2

    28/34

    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 parameterBetween.

    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

  • 8/7/2019 Access2007_M2

    29/34

  • 8/7/2019 Access2007_M2

    30/34

    Hillsborough Community College - Professional Development and Web Services

    24

    5. Sort records, up to four elds in ascending or

    descending order, and click on Next. In this

    example, the elds LastName and FirstName,

    are sorted in ascending order.

    6. Choose a report layout and orientation and clickon 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 reports design and click on Finish.

    e.g. rptEmployeeInfo

    9. The Employee Information report now appears.

    6

    7

    5

    8

    9

  • 8/7/2019 Access2007_M2

    31/34 25

    Microsoft Access 2007 - Module I

    Modify a Report

    Design View and Layout View allow forthe modication and customizing of reportsby adding a logo or picture, organizingheaders, footers, and sorting columns

    In this example, the Employee Information

    report is modied.

    . 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 alarger 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 anobject and drag it to the new location, whileyou are in Design View or Layout ViewYou 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

  • 8/7/2019 Access2007_M2

    32/34

  • 8/7/2019 Access2007_M2

    33/34 27

    Microsoft Access 2007 - Module I

    Resize Image/Graphic

    Sometimes after an image is placed on aform or report, it does not t properly in itsbox Below are the steps to resize an imagewithout 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 ts 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

  • 8/7/2019 Access2007_M2

    34/34

    Hillsborough Community College - Professional Development and Web Services