Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at .
-
Upload
oswin-goodman -
Category
Documents
-
view
218 -
download
0
description
Transcript of 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
Access Lesson 5Review of Thursday’s Lesson
• Designing Forms• Formatting Forms• ActiveX Controls• Creating Subforms
2
Access Lesson 5Filtering by Form
• Access provides several ways to filter data• To select precise subsets of information, use Filter by Form
3
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
Access Lesson 5Filter Toolbar
NewObjectUndoPrint
LoadFromQuery
SpellCheck
Cut Paste
CloseFilter
Window
ApplyFilter
HelpDatabaseWindow
ClearGrid
SaveAs
Query
Copy
FormatPainter
5
Access Lesson 5Filtering by Form
• Enter the search criteria in the form• Click the Apply Filter button
Like“*Manager*”
6
Access Lesson 5Filtering by Form
• When the filter is applied, all contacts who have “Manager” anywhere in their title are displayed
FilterApplied
7
Access Lesson 5Filtering by Form
• Mathematical criteria can also be applied
>100
8
Access Lesson 5Filtering by Form
• When the filter is applied, all products with more than 100 units in stock are displayed
9
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
Access Lesson 5Applying More than One Filter
• When the filter is applied, all condiments with more than 100 units in stock are displayed
11
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
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
Access Lesson 5Advanced Filter/Sort
• For even more complicated sorting, select Records, then Filters, and choose Advanced Filter/Sort from the submenu
14
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
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
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
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
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
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
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
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
Access Lesson 5Creating Queries
• In the “Queries” tab, click “New”
QueriesTab
New
23
Access Lesson 5Simple Query Wizard
• To create a select query, choose the Simple Query Wizard• Click “OK”
24
Access Lesson 5Simple Query Wizard
• Queries can include fields from more than one table
ProductsTable
ProductNameUnitsInStock
FieldsSuppliers
Table
CompanyNameField
25
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
Access Lesson 5Simple Query Wizard
• Choose a name for the new query• Click “Finish”• Choose to open the query and view information
27
Access Lesson 5Simple Query Wizard
• The completed query gathers the requested information from related tables and presents it in compact form
28
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
Access Lesson 5Sorting Queries in Design View
• The query is resorted by Product Name, ascending
30
Access Lesson 5Query Design Toolbar
HelpDatabaseWindow
BuildShowTable
RunPrintPreview
Save Copy
FormatPainter
TopValues
NewObjectUndoPrintView
SpellCheck
CutPaste
QueryType
Properties
Totals
31
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
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
Access Lesson 5Setting Query Criteria
• The effect of restricting products to those beginning with the letter “B”
34
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
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
Access Lesson 5Crosstab Query
• Continue to move through the query wizard
37
Access Lesson 5Crosstab Query
• Choose a name for the new query• Click “Finish”• Choose to open the query and view information
38
Access Lesson 5Crosstab Query
• The completed select query
39
Access Lesson 5Crosstab Query
• Begin a new query, and select Crosstab Query Wizard• Click “OK”
40
Access Lesson 5Crosstab Query
• In this dialog box, select “Queries” and choose the new select query
Just-CreatedSelect QueryView
Queries
41
Access Lesson 5Crosstab Query
• Select “ProductName” and CustomerID as Row Headings• Row headings provide the row data and the sort order
ProductNameCustomerID
RowHeadings
42
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
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
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
Access Lesson 5Crosstab Query
• Choose a name for the new crosstab query• Click “Finish”• Choose to open the query and view information
46
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
Access Lesson 5Find Duplicates Query
• Begin a new query, and select Find Duplicates Query Wizard• Click “OK”
48
Access Lesson 5Find Duplicates Query
• Pick the fields likely to have duplicate entries
City
49
Access Lesson 5Find Duplicates Query
• Choose a name for the new query• Click “Finish”• Choose to open the query and view information
50
Access Lesson 5Find Duplicates Query
• The completed query shows how many times each city appears in the customers table
51
Access Lesson 5Unmatched Query
• Begin a new query, and select Find Unmatched Query Wizard• Click “OK”
52
Access Lesson 5Unmatched Query
• Select two related tables where there might be unmatched records
53
Access Lesson 5Unmatched Query
• Select two related tables where there might be unmatched records
54
Access Lesson 5Unmatched Query
• Indicate which field links the two tables• Access attempts to do this automatically
55
Access Lesson 5Unmatched Query
• Select all fields to be in the results
56
Access Lesson 5Unmatched Query
• Choose a name for the new query• Click “Finish”• Choose to open the query and view information
57
Access Lesson 5Unmatched Query
• In this instance, no unmatched data is found• Referential integrity prevents unmatched data!
58
Access Lesson 5Parameter Query
• Begin a new query, and select Design View• Click “OK”
59
Access Lesson 5Parameter Query
• Choose the table which will be searched
60
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
Access Lesson 5Parameter Query
• The completed query finds the contact name and its related information
62
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
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
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