65
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Embed Size (px)

DESCRIPTION

Access Lesson 5 Filtering by Form Access provides several ways to filter data To select precise subsets of information, use Filter by Form 3

Citation preview

Page 1: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Microsoft Access Lesson 5

Lexington Technology CenterFebruary 25, 2003

Bob Herring

On the Web at www.lexington1.net/AdultEd/computer/microsoft_access.htm

Page 2: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Review of Thursday’s Lesson

• Designing Forms• Formatting Forms• ActiveX Controls• Creating Subforms

2

Page 3: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filtering by Form

• Access provides several ways to filter data• To select precise subsets of information, use Filter by Form

3

Page 4: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filtering by Form

• Click the Filter by Form button• A miniature of the table appears with blanks to enter selection criteria

Mini-Table

CriteriaTab 4

Page 5: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filter Toolbar

NewObjectUndoPrint

LoadFromQuery

SpellCheck

Cut Paste

CloseFilter

Window

ApplyFilter

HelpDatabaseWindow

ClearGrid

SaveAs

Query

Copy

FormatPainter

5

Page 6: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filtering by Form

• Enter the search criteria in the form• Click the Apply Filter button

Like“*Manager*”

6

Page 7: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filtering by Form

• When the filter is applied, all contacts who have “Manager” anywhere in their title are displayed

FilterApplied

7

Page 8: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filtering by Form

• Mathematical criteria can also be applied

>100

8

Page 9: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filtering by Form

• When the filter is applied, all products with more than 100 units in stock are displayed

9

Page 10: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Applying More than One Filter

• More than one criterion can be used in the filter• Add other criteria in the other blanks in the mini-table• This is the “AND” logical condition

>100Condiments

10

Page 11: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Applying More than One Filter

• When the filter is applied, all condiments with more than 100 units in stock are displayed

11

Page 12: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Using the “OR” Property

• Click the “Or” tab at the bottom of the window• This opens a new window with a new mini-table• Enter criteria as before

Grains/Cereals

OrTab 12

Page 13: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Using the “OR” Property

• When the filter is applied, all condiments with more than 100 units in stock and all grains/cereals products are displayed

13

Page 14: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Advanced Filter/Sort

• For even more complicated sorting, select Records, then Filters, and choose Advanced Filter/Sort from the submenu

14

Page 15: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Advanced Filter/Sort

• If a filter is currently in use, it will be shown in the window• Fields to be filtered are shown in columns• Filter conditions can be entered below the field name

>50

15

Page 16: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Advanced Filter/Sort

• When the filter is applied, all condiments with more than 100 units in stock and all grains/cereals products with more than 50 units in stock are displayed

16

Page 17: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5What is a Query?

• A set of explicit specifications to tell Access exactly what information (and in what format) the user wishes to see • The result of a query is a dynaset, or dynamic subset of the records

• Example uses:

• View information from multiple tables sorted in a specific order• Perform many types of calculations on selected groups of records• Find and display duplicate or unmatched records• Update data, delete records, or append new records to a table• Create a new table with records from one or more tables

17

Page 18: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Kinds of Queries

• Select Queries

• Simple Select: Displays information from one or more tables sorted in a specific order• Find Duplicate: Displays all records with duplicate values in one or more specified fields• Find Unmatched: Displays records in one table that have no related records in another table

18

Page 19: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Kinds of Queries

• Special Purpose Queries

• Parameter: Displays a dialog box to enter criteria for retrieving information• AutoLookup: Automatically fills in values in a new record• Crosstab: Calculates a sum or counts and groups its results in spreadsheet format to correlate the data with two types of information

19

Page 20: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Kinds of Queries

• Action Queries

• Update: Makes global changes to a group of records in one or more tables• Append: Adds a group of records from one or more tables to the end of one or more other tables• Delete: Removes a group of records from one or more tables• Make Table: Creates a new table from data from one or more tables

20

Page 21: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Kinds of Queries

• SQL-Specific Queries

• Union: Combines fields from one or more tables into one field in the result• Pass-Through: Sends commands to an ODBC server• Data-Definition: Creates or changes database objects in Access, SQL-Server, or databases on other servers• Subqueries: SQL SELECT or other server statements that form a SELECT query within another query

21

Page 22: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Filters vs. Queries

• Use a filter when:• Working within one table• Working on a temporary subset of the table’s records

• Use a query when:• Records will come from more than one table• You will “ask the same question” again• You don’t want to have to open a table or form• You want an answer calculated from the data in the table(s)• You want to create a new table from the result

22

Page 23: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Creating Queries

• In the “Queries” tab, click “New”

QueriesTab

New

23

Page 24: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Simple Query Wizard

• To create a select query, choose the Simple Query Wizard• Click “OK”

24

Page 25: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Simple Query Wizard

• Queries can include fields from more than one table

ProductsTable

ProductNameUnitsInStock

FieldsSuppliers

Table

CompanyNameField

25

Page 26: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Simple Query Wizard

• Select the detail view if all fields will be shown• Summary is for fields with numbers that can be manipulated

26

Page 27: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Simple Query Wizard

• Choose a name for the new query• Click “Finish”• Choose to open the query and view information

27

Page 28: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Simple Query Wizard

• The completed query gathers the requested information from related tables and presents it in compact form

28

Page 29: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Sorting Queries in Design View

• If the information isn’t sorted to the user’s liking, it can be resorted• Click the Design View button to see the query’s design• Set the correct sort in the sort row of the column that the query should be sorted by

Sort: Ascending

29

Page 30: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Sorting Queries in Design View

• The query is resorted by Product Name, ascending

30

Page 31: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Query Design Toolbar

HelpDatabaseWindow

BuildShowTable

RunPrintPreview

Save Copy

FormatPainter

TopValues

NewObjectUndoPrintView

SpellCheck

CutPaste

QueryType

Properties

Totals

31

Page 32: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Setting Query Criteria

• Criteria may be built using the Expression Builder• This tool holds all the Tables and Queries, standard Access functions and common expressions, as well as buttons to add operators and logical statements

32

Page 33: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Setting Query Criteria

• Click an operator button to enter it in the expression window• Click on field names or functions to put them in the window• Type other needed information using the keyboard

Like“B*”

Like“B*”

33

Page 34: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Setting Query Criteria

• The effect of restricting products to those beginning with the letter “B”

34

Page 35: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• To begin creating a crosstab query, create a simple query that contains the fields you want to include• Select the Simple Query Wizard and click “OK”

35

Page 36: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Move from table to table collecting the fields that will be included in the eventual crosstab query• A crosstab query must have at least four fields to work with

Products TableOrder DetailsTable

OrderTable

36

Page 37: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Continue to move through the query wizard

37

Page 38: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Choose a name for the new query• Click “Finish”• Choose to open the query and view information

38

Page 39: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• The completed select query

39

Page 40: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Begin a new query, and select Crosstab Query Wizard• Click “OK”

40

Page 41: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• In this dialog box, select “Queries” and choose the new select query

Just-CreatedSelect QueryView

Queries

41

Page 42: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Select “ProductName” and CustomerID as Row Headings• Row headings provide the row data and the sort order

ProductNameCustomerID

RowHeadings

42

Page 43: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Use OrderDate as the Column Heading• The columns contain the time location of the data that will be tabulated

OrderDate

ColumnHeadings

43

Page 44: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Choose to view the results by quarter• Note that the column heading changes to quarters• The quarter data is obtained automatically from the OrderDate field

Quarter

ColumnHeadings

44

Page 45: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• For the calculated part, choose “Sum”• This will sum up the orders by Product by Customer by Quarter

Sum

Sum(Quantity)

45

Page 46: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• Choose a name for the new crosstab query• Click “Finish”• Choose to open the query and view information

46

Page 47: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Crosstab Query

• The completed crosstab query shows each product and the quantity that each customer purchased, both in total and by quarter

47

Page 48: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Find Duplicates Query

• Begin a new query, and select Find Duplicates Query Wizard• Click “OK”

48

Page 49: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Find Duplicates Query

• Pick the fields likely to have duplicate entries

City

49

Page 50: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Find Duplicates Query

• Choose a name for the new query• Click “Finish”• Choose to open the query and view information

50

Page 51: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Find Duplicates Query

• The completed query shows how many times each city appears in the customers table

51

Page 52: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• Begin a new query, and select Find Unmatched Query Wizard• Click “OK”

52

Page 53: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• Select two related tables where there might be unmatched records

53

Page 54: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• Select two related tables where there might be unmatched records

54

Page 55: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• Indicate which field links the two tables• Access attempts to do this automatically

55

Page 56: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• Select all fields to be in the results

56

Page 57: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• Choose a name for the new query• Click “Finish”• Choose to open the query and view information

57

Page 58: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Unmatched Query

• In this instance, no unmatched data is found• Referential integrity prevents unmatched data!

58

Page 59: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Parameter Query

• Begin a new query, and select Design View• Click “OK”

59

Page 60: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Parameter Query

• Choose the table which will be searched

60

Page 61: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Parameter Query

• Insert the fields that will be shown in the query• In the “Criteria” line, enter the prompt in square brackets [ ]• Click the “Run” button

[EnterContactName]

Type thevalue to besearched for

61

Page 62: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Parameter Query

• The completed query finds the contact name and its related information

62

Page 63: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Union Query

• A union query merges similar data into one field• Union Queries are created by writing SQL statements• Click the view button and choose SQL view

SQL View

63

Page 64: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Union Query

• The SQL view shows the statements that comprise the query• All queries are really SQL statements; Access hides the details to make it easier for the user• Space can be saved in the database by writing SQL rather than saving queries

64

Page 65: Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at

Access Lesson 5Review

• Filter by Form• Using “And” and “Or” to Filter• Advanced Filter/Sort• Queries

• Select Queries• Query Criteria• Crosstab Queries• Find Duplicates Queries• Find Unmatched Queries• Parameter Queries• Union Queries

65