access chapter 2

Download Access Chapter 2

If you can't read please download the document

Upload: cael

Post on 25-Feb-2016

26 views

Category:

Documents


1 download

DESCRIPTION

Access Chapter 2. Querying a Database. Objectives. Create queries using the Simple Query Wizard Print query results Create queries using Design view Include fields in the design grid Use text and numeric data in criteria. Objectives. Create and use parameter queries - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

Access Chapter 2Querying a DatabaseMicrosoft Office 2007ObjectivesCreate queries using the Simple Query WizardPrint query resultsCreate queries using Design viewInclude fields in the design gridUse text and numeric data in criteria2Microsoft Office 2007: Introductory Concepts and Techniques - Windows Vista EditionObjectivesCreate and use parameter queriesSave a query and use the saved queryUse compound criteria in queriesSort data in queriesJoin tables in queries

Microsoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition3ObjectivesCreate a report from a queryPerform calculations in queriesCalculate statistics in queriesCreate crosstab queriesCustomize the Navigation pane

Microsoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition4Plan AheadIdentify the fieldsIdentify restrictionsDetermine whether special order is requiredDetermine whether more than one table is requiredDetermine whether calculations are requiredIf data is to be summarized, determine whether a crosstab query would be appropriateMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition5Starting AccessClick the Start button on the Windows Vista taskbar to display the Start menuClick All Programs at the bottom of the left Pane on the Start menu to display the All Programs list and then click Microsoft Office in the All Programs list to display the Microsoft Office listClick Microsoft Office Access 2007 on the Microsoft Office list to start Access and display the Getting Started with Microsoft Office Access windowIf the Access window is not maximized, click the Maximize button on its title bar to maximize the windowMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition6Opening a DatabaseWith your USB flash drive connected to one of the computers USB ports, click the More button to display the Open dialog boxIf the Folders list is displayed below the Folders button, click the Folders button to remove the Folders listIf necessary, click Computer in the Favorite Links section and then double-click UDISK 2.0 (E:) to select the USB fl ash drive, Drive E in this case, as the new open location. (Your drive letter might be different.)Click JSP Recruiters to select the fi le nameMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition7Opening a DatabaseClick the Open button to open the databaseIf a Security Warning appears, click the Options button to display the Microsoft Office Security Options dialog boxWith the option button to enable this content selected, click the OK button to enable the contentMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition8Using the Simple Query Wizard to Create a QueryIf the Navigation pane is hidden, click the Shutter Bar Open/Close Button to show the Navigation paneBe sure the Client table is selectedClick Create on the Ribbon to display the Create tabClick the Query Wizard button on the Create tab to display the New Query dialog boxBe sure Simple Query Wizard is selected, and then click the OK button to display the Simple Query Wizard dialog boxClick the Add Field button to add the Client Number fieldMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition9Using the Simple Query Wizard to Create a QueryClick the Add Field button a second time to add the Client Name fieldClick the Recruiter Number field, and then click the Add Field button to add the Recruiter Number fieldClick the Next buttonBe sure the title of the query is Client QueryClick the Finish button to create the queryClick the Close button for the Client Query to remove the query results from the screenMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition10Using the Simple Query Wizard to Create a QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition11

Using a Criterion in a QueryRight-click Client Query to produce a shortcut menuClick Design View on the shortcut menu to open the query in Design viewClick the Criteria row in the Recruiter Number column of the grid, and then type 24 as the criterionClick the View button to display the results in Datasheet viewClose the Client Query window by clicking the Close Client Query buttonWhen asked if you want to save your changes, click the No buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition12Using a Criterion in a QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition13

Printing the Results of a QueryWith the Client Query selected in the Navigation pane, click the Office ButtonPoint to Print on the Office button menuClick Quick Print on the Print submenuMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition14Creating a Query in Design ViewHide the Navigation paneClick Create on the Ribbon to display the Create tabClick the Query Design button to create a new queryWith the Client table selected, click the Add button in the Show Table dialog box to add the Client table to the queryClick the Close button in the Show Table dialog box to remove the dialog box from the screenDrag the lower edge of the field box down far enough so all fields in the Client table appearMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition15Creating a Query in Design ViewMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition16

Adding Fields to the Design GridDouble-click the Client Number field in the field list to add the Client Number field to the queryDouble-click the Client Name field in the field list to add the Client Name field to the queryAdd the Amount Paid field to the query by double-clicking the Amount Paid field in the field listAdd the Current Due field to the queryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition17Adding Fields to the Design GridMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition18

Using Text Data in a CriterionClick the Criteria row for the Client Number field to produce an insertion pointType FD89 as the criterionClick the View button to display the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition19

Using a WildcardClick the View button to return to Design viewIf necessary, click the Criteria row below the Client Number field to produce an insertion pointUse the DELETE or BACKSPACE key as necessary to delete the current entryClick the Criteria row below the Client Name field to produce an insertion pointType Be* as the criterionView the query results by clicking the View buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition20Using a WildcardMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition21

Using Criteria for a Field Not Included in the ResultsClick the View button to return to Design viewErase the criterion in the Client Name fieldInclude the City field in the queryType Berridge as the criterion for the City fieldClick the Show check box for the City field to remove the check markView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition22Using Criteria for a Field Not Included in the ResultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition23

Creating a Parameter QueryReturn to Design viewErase the current criterion in the City column, and then type [Enter City] as the new criterionClick the View button to display the Enter Parameter Value dialog boxType Fort Stewart as the parameter value in the Enter City text box and then click the OK buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition24Creating a Parameter QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition25

Saving a QueryClick the Save button on the Quick Access Toolbar to open the Save As dialog boxType Client-City Query in the Query Name text boxClick the OK button to save the queryClick the Close Client-City Query button to close the query and remove it from the screenMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition26Saving a QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition27

Using a Saved QueryShow the Navigation paneRight-click the Client-City Query to produce a shortcut menuClick Open on the shortcut menu to open the query and display the Enter Parameter Value dialog boxType Fort Stewart in the Enter City text box, and then click the OK button to display the results using Fort Stewart as the city as shown in Figure 224 on the previous slide Click the Close Client-City Query button, shown in Figure 224, to close the queryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition28Using a Saved QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition29

Using a Number in a CriterionHide the Navigation paneClick Create on the Ribbon to display the Create tabClick the Query Design button to create a new queryWith the Client table selected, click the Add button in the Show Table dialog box to add the Client table to the queryClick the Close button in the Show Table dialog box to remove the dialog box from the screenMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition30Using a Number in a CriterionDrag the lower edge of the field box down far enough so all fields in the Client table are displayedInclude the Client Number, Client Name, Amount Paid, and Current Due fields in the queryType 0 as the criterion for the Current Due fieldView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition31Using a Number in a CriterionMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition32

Using a Comparison Operator in a CriterionReturn to Design viewErase the 0 in the Current Due columnType >20000 as the criterion for the Amount Paid fieldView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition33Using a Comparison Operator in a CriterionMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition34

Using a Compound Criterion Involving ANDReturn to Design viewInclude the Recruiter Number field in the queryType 21 as the criterion for the Recruiter Number fieldView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition35Using a Compound Criterion Involving ANDMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition36

Using a Compound Criterion Involving ORReturn to Design viewIf necessary, click the Criteria entry for the Recruiter Number field and then use the BACKSPACE key or the DELETE key to erase the entry (21)Click the or: row (the row below the Criteria row) for the Recruiter Number field and then type 21 as the entryView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition37Using a Compound Criterion Involving ORMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition38

Clearing the Design GridReturn to Design viewClick just above the Client Number column heading in the grid to select the columnHold the SHIFT key down and click just above the Recruiter Number column heading to select all the columnsPress the DELETE key to clear the design gridMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition39Clearing the Design GridMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition40

Sorting Data in a QueryInclude the City field in the design gridClick the Sort row below the City field, and then click the Sort row arrow to display a menu of possible sort ordersClick Ascending to select Ascending sort orderView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition41Sorting Data in a QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition42

Omitting DuplicatesReturn to Design viewClick the second field in the design grid (the empty field following City)If necessary, click Design on the Ribbon to display the Design tabClick the Property Sheet button on the Design tab to display the property sheetMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition43Omitting DuplicatesClick the Unique Values property box, and then click the arrow that appears to produce a menu of available choices for Unique ValuesClick Yes and then close the Query Properties sheet by clicking its Close buttonView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition44Omitting DuplicatesMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition45

Sorting on Multiple KeysReturn to Design viewClear the design gridInclude the Client Number, Client Name, Recruiter Number, and Amount Paid fields in the query in this orderSelect Ascending as the sort order for both the Recruiter Number field and the Amount Paid fieldView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition46Sorting on Multiple KeysMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition47

Creating a Top-Values QueryReturn to Design viewIf necessary, click Design on the Ribbon to display the Design tabClick the Return box arrow on the Design tab to display the Return box menuClick 5 in the Return box menu to specify that the query results should contain the first five rowsView the query resultsClose the query by clicking the Close Query1 buttonWhen asked if you want to save your changes, click the No buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition48Creating a Top-Values QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition49

Joining TablesClick Create on the Ribbon to display the Create tabClick the Query Design button to create a new queryClick the Recruiter table in the Show Table dialog box to select the tableClick the Add button to add a field list for the Recruiter table to the queryClick the Client table in the Show Table dialog boxClick the Add button to add a field list for the Client tableMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition50Joining TablesClose the Show Table dialog box by clicking the Close buttonExpand the size of the field lists so all the fields in the Recruiter and Client tables appearIn the design grid, include the Recruiter Number, Last Name, and First Name fields from the Recruiter table as well as the Client Number and Client Name fields from the Client tableSelect Ascending as the sort order for both the Recruiter Number field and the Client Number fieldView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition51Joining TablesMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition52

Saving the QueryClick the Save button on the Quick Access Toolbar to display the Save As dialog boxType Recruiter-Client Query as the query nameClick the OK button to save the queryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition53Saving the QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition54

Changing Join PropertiesReturn to Design viewRight-click the join line to produce a shortcut menuClick Join Properties on the shortcut menu to display the Join Properties dialog boxClick option button 2 to include all records from the Recruiter table regardless of whether they match any clientsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition55Changing Join PropertiesClick the OK buttonView the query results by clicking the View buttonClick the Save button on the Quick Access ToolbarClose the Recruiter-Client Query by clicking the Close Recruiter-Client Query buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition56Changing Join PropertiesMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition57

Creating a Report Involving a JoinShow the Navigation pane and be sure the Recruiter-Client Query is selected in the Navigation paneClick Create on the Ribbon to display the Create tabClick the Report Wizard button to display the Report Wizard dialog boxClick the Add All Fields button to add all the fields in the Recruiter-Client QueryClick the Next button to display the next Report Wizard screenMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition58Creating a Report Involving a JoinBecause you will not specify any grouping, click the Next button in the Report Wizard dialog box to display the next Report Wizard screenBecause you already specified the sort order in the query, click the Next button again to display the next Report Wizard screenMake sure that Tabular is selected as the Layout and Portrait is selected as the OrientationClick the Next button to display the next Report Wizard screenBe sure the Module style is selectedMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition59Creating a Report Involving a JoinClick the Next button to display the next Report Wizard screenErase the current title, and then type Recruiter-Client Report as the new titleClick the Finish button to produce the reportClick the Close button for the Recruiter-Client Report to remove the report from the screenMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition60Creating a Report Involving a JoinMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition61

Printing a ReportWith the Recruiter-Client Report selected in the Navigation pane, click the Office Button, point to Print on the Office button menu, and then click Quick Print on the Print submenu to print the reportMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition62Restricting the Records in a JoinOpen the Recruiter-Client Query in Design view and hide the Navigation paneAdd the Amount Paid field to the queryType >20000 as the criterion for the Amount Paid field and then click the Show check box for the Amount Paid field to remove the check markView the query resultsClose the query by clicking the Close Recruiter-Client Query buttonWhen asked if you want to save your changes, click the No buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition63Restricting the Records in a JoinMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition64

Using a Calculated Field in a QueryCreate a query with a field list for the Client tableAdd the Client Number, Client Name, Amount Paid, and Current Due fields to the queryRight-click the Field row in the first open column in the design grid to display a shortcut menuClick Zoom on the shortcut menu to display the Zoom dialog boxMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition65Using a Calculated Field in a QueryType Total Amount:[Amount Paid]+[Current Due] in the Zoom dialog boxClick the OK button to enter the expressionView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition66Using a Calculated Field in a QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition67

Changing a CaptionReturn to Design viewClick Design on the Ribbon to display the Design tabClick the Amount Paid field in the design grid, and then click the Property Sheet button on the Design tabClick the Caption box, and then type Paid as the captionClose the property sheet by clicking its Close buttonClick the Current Due field in the design grid, and then click the Property Sheet button on the Design tabMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition68Changing a CaptionClick the Caption box, and then type Due as the captionClose the Property Sheet by clicking its Close buttonView the query resultsClick the Close Query1 button to close the queryWhen asked if you want to save your changes, click the No buttonMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition69Changing a CaptionMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition70

Calculating StatisticsCreate a new query with a field list for the Client tableIf necessary, click Design on the Ribbon to display the Design tabAdd the Amount Paid field to the queryClick the Totals button on the Design tab to include the Total row in the design gridMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition71Calculating StatisticsClick the Total row in the Amount Paid column to display the Total box arrowClick the Total box arrow to display the Total listClick Avg to indicate that Access is to calculate an averageView the queryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition72Calculating StatisticsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition73

Using Criteria in Calculating StatisticsReturn to Design viewInclude the Recruiter Number field in the design gridClick the Total box arrow in the Recruiter Number column to produce a Total listClick WhereType 21 as the criterion for the Recruiter Number fieldView the query resultsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition74Using Criteria in Calculating StatisticsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition75

Using GroupingReturn to Design view and clear the design gridInclude the Recruiter Number field in the queryInclude the Amount Paid field in the querySelect Avg as the calculation in the Total row for the Amount Paid fieldView the query resultsClose the queryDo not save your changesMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition76Using GroupingMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition77

Creating a Crosstab QueryClick Create on the Ribbon to display the Create tabClick the Query Wizard button to display the New Query dialog boxClick Crosstab Query Wizard in the New Query dialog boxClick the OK button to display the Crosstab Query WizardWith the Tables option button selected and the Client table selected, click the Next button to display the next Crosstab Query Wizard screenMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition78Creating a Crosstab QueryClick the City field, and then click the Add Field button to select the City field for row headingsClick the Next button to display the next Crosstab Query Wizard screenClick the Recruiter Number field to select the Recruiter Number field for column headingsClick the Next button to display the next Crosstab Query Wizard screenClick the Amount Paid field to select the Amount Paid field for calculationsMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition79Creating a Crosstab QueryClick Sum to select Sum as the calculation to be performedClick the Next button to display the next Crosstab Query Wizard screenType Client-Recruiter Crosstab as the name of the queryClick the Finish button to produce the crosstab shown in Figure 275 on page AC 122Close the queryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition80Creating a Crosstab QueryMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition81

Customizing the Navigation PaneIf necessary, click the Shutter Bar Open/Close Button to show the Navigation paneClick the Navigation pane arrow to produce the Navigation pane menuClick Object Type to organize the Navigation pane by the type of object rather than by tableClick the Navigation pane arrow to produce the Navigation pane menuClick Tables and Related Views to once again organize the Navigation pane by tableMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition82Customizing the Navigation PaneMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition83

Quitting AccessClick the Close button on the right side of the Access title bar to quit AccessMicrosoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition84SummaryCreate queries using the Simple Query WizardPrint query resultsCreate queries using Design viewInclude fields in the design gridUse text and numeric data in criteria85Microsoft Office 2007: Introductory Concepts and Techniques - Windows Vista EditionSummaryCreate and use parameter queriesSave a query and use the saved queryUse compound criteria in queriesSort data in queriesJoin tables in queries

Microsoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition86SummaryCreate a report from a queryPerform calculations in queriesCalculate statistics in queriesCreate crosstab queriesCustomize the Navigation pane

Microsoft Office 2007: Introductory Concepts and Techniques - Windows Vista Edition87Access Chapter 2 CompleteMicrosoft Office 2007