Download - Access Queries IV - cs101.wvu.edu · Copy Query •In the Query Objects you should see your copied query •The copied query will be identical to the original query in design and

Transcript

Created by Denny Hood

Access Queries IVComputer Science 101, WVU

Table of Contents

• Use Existing Query

in New Query

• Copy Query

• Wildcard Queries

• Unique Values Query

• Parameter Query

• Updating Records Query

• Delete Records Query

Use Existing Query in New Query

• Create ribbon

• Query Design

• Show Table• Queries Tab

• Add existing query

Use Existing Query in New Query

• Add fields from existing query

• Click Run

Use Existing Query in New Query

• The new query will only show added fields from the old query

Copy Query

• Click the query in Query Objects

• Right click

• Select Copy

• Right click in white space in Query Objects

• Select Paste

Copy Query

• Rename “Copy Of QueryXX” to new name

• Click OK

Copy Query

• In the Query Objects you shouldsee your copied query

• The copied query will be identical to the original query in design and datasheet views

Use Wildcards In Query Criteria

• Create Ribbon

• Query Design

• Add fields to query

• In the criteria row for wildcard:• Like keyword

• * text before (may or may not need it)

• text word we are looking for

• * text after (may or may not need it)

Use Wildcards In Query Criteria

• Click Run

• After you run the query,you will only see resultsthat meet the wildcardcriteria

• In this example, the Counties field must have a (P) somewhere in it

Display Unique Values In Query

• Create ribbon

• Query design

• Add fields to query

• In the gray space of thequery, right click• Choose Properties…

Display Unique Values In Query

• In the Property Sheet, make sure the Selection type: Query Properties is shown

• Change the Unique Values to Yes

• Close the Property Sheet

• Click Run

Display Unique Values In Query

• After you run the query, no two records will be alike

• In this example, the query will only show each name one time even if they won more than one election

Use Parameters In A Query

• Create Ribbon

• Query Design

• Add fields to query

• In the criteria row:• [

• “text to display on screen”

• ]“text to display on screen” Is what you want to display to prompt the user for input

Use Parameters In A Query

• Click Run

• In this example, the prompt says “Enter the Election Year”

• Enter a valid year

• Click OK

Use Parameters In A Query

• In this example only the records for 2012 are shown

• We can run this query again and input a different year to see the election results for that year instead of opening the query in design view and changing the criteria each time

Updating Records Query

• WARNING: update records query will change data in your tables PERMANENTLY

• In this example, we are going to update the Year field for the record with Incumbent name “Denny Hood”

Updating Records Query

• Create ribbon

• Query Design

• Add table with record to update

• Change Query Type to Update inthe Query Type Group

• Add Update To: value and Criteria: value

We are going to change the year in the Elections table for records with 1999 to 2016

Updating Records Query

• Click Run

• Access will warn you about how many rows are going to be updated

• Click Yes

Updating Records Query

• In this example, the record with 1999 as the year has been updated and now the year is 2016

Delete Records Query

• WARNING: delete records query will remove data from your tables PERMANENTLY

• In this example, we are going to remove the record with Incumbent name “Denny Hood”

Delete Records Query

• Create ribbon

• Query Design

• Add table with records to remove

• Add field(s) that contain values in records you want to remove

• Change Query Type to Delete in the Query Type Group

• Add the criteria for records you wish to delete

Delete Records Query

• Click Run

• Access will warn you about how many records are going to be deleted

• Click Yes

Delete Records Query

• In this example, the record with “Denny Hood” as the Incumbent name has been removed and now there is one less record in the table