Sunteți pe pagina 1din 9

Offered by the Center for Teaching and Learning @ UIS

Page 1
INTERMEDIATE ACCESS II

EXPORTING ACCESS TO EXCEL .............................................................................................................................................. 2
STEPS TO EXPORT ACCESS DATA TO EXCEL .................................................................................................................................... 2
REFRESHING THE DATA.................................................................................................................................................................. 2
IMPORTING EXCEL INTO ACCESS .......................................................................................................................................... 2
ADVANCED QUERIES.................................................................................................................................................................. 3
Stopping a Query....................................................................................................................................................................... 3
ACTION QUERIES ........................................................................................................................................................................... 3
Update Query............................................................................................................................................................................ 3
Delete Query............................................................................................................................................................................. 4
Make Table Query..................................................................................................................................................................... 4
Append Query ........................................................................................................................................................................... 5
CROSSTAB QUERY.......................................................................................................................................................................... 5
PATTERN MATCH............................................................................................................................................................................ 6
Pattern Match Structure ............................................................................................................................................................ 6
Wildcards to use with Like......................................................................................................................................................... 6
LIST-OF-VALUES MATCH................................................................................................................................................................. 6
In comparison operator ............................................................................................................................................................. 6
Syntax ....................................................................................................................................................................................... 6
Non-matching value................................................................................................................................................................... 6
Syntax ....................................................................................................................................................................................... 6
COMPOUND CONDITIONS USING AND AND OR ............................................................................................................................... 7
PARAMETER QUERY........................................................................................................................................................................ 7
EXPRESSION BUILDER............................................................................................................................................................... 8
PARTS OF THE EXPRESSION BUILDER .............................................................................................................................................. 8
Top ........................................................................................................................................................................................... 8
Middle....................................................................................................................................................................................... 8
Bottom ...................................................................................................................................................................................... 8
ACCESSING THE EXPRESSION BUILDER............................................................................................................................................ 8
CREATING CALCULATED FIELDS IN QUERIES.................................................................................................................... 9
CUSTOM CALCULATION.................................................................................................................................................................. 9
Renaming the Calculated Field.................................................................................................................................................. 9
USING THE TOTAL ROW TO CREATE CALCULATIONS ....................................................................................................................... 9
Renaming the Field Name.......................................................................................................................................................... 9
Offered by the Center for Teaching and Learning @ UIS
Page 2 03/13/2000
Step 7 - Choose the spreadsheet that contains the data
you want to import
Tables and fields that you can bring into Excel from Access
EXPORTING ACCESS TO EXCEL
You can use familiar Excel tools such as the Chart Wizard or automatic subtotals to present and summarize the data, in
ways that you could not (at least not very easily) in the database. You can format the data, and your formatting is
retained when you refresh the external data from the source database.
Many users import data into Excel through database queries and analyze the data with formulas and formatting. In Excel
2000, users can insert columns within query tables and apply formulas and formatting; when the data is refreshed, the
formatting and analysis is retained.
Steps to Export Access Data to Excel
1. Open an Excel Workbook
2. Data, Get External Data, Database Query
3. Choose the type of data, [OK]
4. Locate the database, [OK]
5. From within the Choose Columns box, click the plus
sign [+] to expand tables.
6. When a table is expands, select the fields of
information that you want to bring into the
spreadsheet.
7. Click the right arrow to transfer them into the Excel
query. [Next]
8. Filter data (if applicable). [Next]
9. Sort data on one or more fields (if applicable). [Next].
10. In the Finish box, click the Save Query button if you
plan to run this query again, then choose to Return Data to Excel. [Finish]
Refreshing the Data
When the information in the database changes, open the excel worksheet that contains the query, click anywhere in the
query, then click the refresh button.
IMPORTING EXCEL INTO ACCESS
Importing data creates a copy of the current spreadsheet
information in a new table in Access. The spreadsheet
information is NOT altered during this process.
It is important that you name the worksheet for easier
identification when you import. To name the worksheet
double-click on the sheet tab, type a name then strike the
Enter key. The worksheet information should be in a list
format and contain headings in row 1 (firstname, lastname,
date, etc).
1. Open Access
2. Start a blank database.
3. Click File, Get External Data, Import
4. Locate the spreadsheet.
5. Within the Open Dialog box, change the View Files of
Type (lower left corner) to Excel (.xls)
6. Double click on the spreadsheet name.
7. The Import Spreadsheet Wizard opens, Show
Worksheets is selected, and to the right are the names of all the sheets in the workbook. Click on the sheet that
contains the data you want to import. [Next]
8. Click before First Row Contains Column Headings. [Next]
9. Select Store in a New Table then click NEXT.
Offered by the Center for Teaching and Learning @ UIS
Page 3 03/13/2000
Step 10 - Select fields that you do NOT want to import
10. Click the column heading for fields you do not want to
import, then click before Do not import field. Repeat for
additional columns that you do not want to import.
A dialog box might appear stating that some of the
information contains invalid field names; this is usually a
result of spacing in the header name.[Next]
11. Click before one of the Primary Key options. [Next]
If you choose to set a primary key based upon one of the
field names, click on the downward pointing arrow next to
this option and select the field.
12. Name the table, and then click FINISH.
13. Open the table in Design View and customize the
properties for each field (size, input mask, etc.)



ADVANCED QUERIES
Stopping a Query
To stop a query after you start it, press CTRL+BREAK
Action Queries
Once in query Design View, you can access several query tools that will perform
specific operations. These queries are called action queries. They are designed to
makes changes to many records in just one operation. There are four types of
action queries: delete, update, append, and make-table. Access the different action
queries using the Query menu.
Update Query
This tool will quickly make global changes to a group of records in one or more
tables.
For example, if you need to change a field value in many tables from
Commodities to Merchandise, use the Update Query to quickly make this
change in all records that contain the value.
Steps:
1. Begin a new query in design view.
2. Add the table that contains the values that you want to change.
3. Click Query, Update Query.
4. Drag the field that contains the values onto the design grid.
5. Click in the Update To box and type the new value.
6. Click in the Criteria box and type the value to be changed.
7. Click the Run button.
8. A dialog box will appear indicating how many records will be changed.
9. Click OK and the change is made. Close the query.
The Query menu contains
several query tools that will perform
specific operations!
Update Query
Clicking the Run button will change
the value of Commodities in the
Account field to Merchandise.
Offered by the Center for Teaching and Learning @ UIS
Page 4 03/13/2000
Make Table Example
Clicking the Run button will copy and paste all records that
have a First Contact date before January 1st '94 to a new table.
Delete Query
This action query will delete a group of records from one or more tables. With
delete queries, you always delete entire records, not just selected fields within
records.
For example, you could use a delete query to remove invoices that are less the
$800.
Steps
1. Begin a new query in design view.
2. Add the table(s) that contain the values that will be deleted.
3. Click Query, Delete Query.
4. For the tables you want to delete records from, drag the asterisk (*) from the
field list to the query design grid.
5. From appears in the Delete cell under these fields, as shown in the Delete
Query Example at the right.
6. To specify criteria for deleting records, drag to the design grid the fields on which you want to set criteria.
7. Where appears in the Delete cell under these fields, as shown in Delete Query Example.
8. In the Criteria box for the fields that you have dragged to the grid, type the criteria.
In the example, it is <800.
9. Click the Run button.
A dialog appears indicating the number of records that match the criteria and that will be deleted.
10. Click OK.
All records in the Orders table that had an Invoice Amount of less that $800 were deleted.
Make Table Query
This action query will create a new table from all or
part of the data in one or more tables. The new table
can be an exact copy, a subset of some of the fields
and records, or a combination of the fields and records
from more than one table.
Use the Make Table query to create:
a table to export to other Access databases.
a backup copy of a table.
a history table that contains old records that
are no longer needed, but you might need to
reference in the future.
Steps:
1. Begin a new query in design view.
2. Add the table(s) that contain the records you
want to put in the new table
3. Click Query, Make Table Query.
The Make Table dialog box appears.
4. In the Table Name box, enter the name of the
table you want to create.
5. Click before Current Database or Another
Database.
If you select Another Database type the entire path next to filename (ex. c:\training\intaccess2)
6. Click OK.
7. Drag the fields you want in the new table onto the query grid.
8. If necessary, enter the Criteria for a field on the gird.
In the Make Table Example, the First Contact field contains data the will determine which records are copied to a
new table.
9. Click the Run button.
A dialog box opens and indicates how many records will be pasted to a new table.
10. Click OK.
Delete Query Example. Records that have
a balance less than 800 will be deleted.
Offered by the Center for Teaching and Learning @ UIS
Page 5 03/13/2000
The field Billing
Date was
selected in step
4 as the field that
will serve as the
row headings. The field
State was
selected in
step 5 as
the field
that will
serve as
the
Column
headings.
The field Invoice Amount was
selected in step 6 as the field that
will be calculated for each row
and column intersection. The
function SUM was also selected.
Crosstab Query Example
Use the Crosstab Wizard to create.
Append Query
This action query will add a group of records from one or more tables to the end of one or more tables. When creating an
append query you choose the fields you want to append from one or more tables; the selected data remains in the original
table.
Steps:
1. Begin a new query in design view.
2. Add the table whose records you want to append to another table.
3. Click Query, Append Query.
4. In the Table Name box, enter the name of the table you want to append records to.
1. Click before Current Database or Another Database.
If you select Another Database type the entire path next to filename (ex. c:\training\intaccess2)
5. Click OK.
2. Drag the fields you want to append and any fields you want to use for setting criteria.
If all the fields in both tables have the same names, you can just drag the asterisk (*) to the query design grid.
6. If the fields you've selected have the same name in both tables, Microsoft Access automatically fills the matching
name in the Append To row. If the fields in the two tables don't have the same name, in the Append To row, enter the
names of the fields in the table you're appending to.
7. In the Criteria cell for the fields that you have dragged to the grid, type the criteria on which additions will be made.
8. To preview the records that the query will append, click View on the toolbar. To return to query Design view, click
View on the toolbar again.
9. Click Run button to add the records.
Crosstab Query
A crosstab query displays summarized values (sums, counts, and averages) from one field in a table and groups them by
one set of facts listed down the left side of the datasheet and another set of facts listed across the top of the datasheet.
The process and result is very similar to PivotTables in Excel. In a crosstab query you can use the following functions;
Avg, Sum, Count, First, Last, Min, Max, StDev, and Var.
The quickest way to create a crosstab query is to use the Crosstab Query Wizard.
Steps:
1. Click the Queries bar to move to that area of the database.
2. Click the New button, then select Crosstab Query Wizard, and OK.
3. Select the table or query that contains the fields that you want in the query. [Next]
4. Select the field that will serve as row headings. [Next]
5. Select the field that will serve as column headings. [Next]
6. Choose the field that will be calculated for each row and column intersection and the function to use for the
calculation.
In the Crosstab example at the intersection of State and Billing Date all fields would be added together.
7. Name the query.


Offered by the Center for Teaching and Learning @ UIS
Page 6 03/13/2000
Pattern Match Example
Use Like"312*" to find
all students who live in
the 312 area code.
Pattern match
This condition will select records that match simple
conditions for selected fields using the Like comparison
operator. Since the Like operator selects from a string
of information one or more wildcard characters is used.
For example, you want to select all records in the 217
area code. In the design grid click in the criteria box for
PHONE and type Like "217*"
Pattern Match Structure
Click in the Criteria box under the field to be queried.
Type (no spaces), Like"condition
wildcard
"
Wildcards to use with Like
! The asterisk is used to represent a string of
characters usually before or after known
characters, such as 756* would display all
phone numbers with the prefix 756.
! The question mark is used to represent a single
alphabetic character and can be placed anywhere in an alphabetic string, such as Johns?n would display last
names of Johnson and Johnsen.
! The number symbol is used to represent a single digit in a numeric field and can be placed anywhere in the
numeric string, such as 23#5 would display values of 2315, 2325, 2345, etc.
List-of-values match
This condition will select records whose value for the
selected field matches one of two or more simple
condition values. This could be accomplished by
using the OR conditions on the query design grid.
For example, you want a listing of students who live
in Springfield OR Chicago. It is usually easier,
though, to use the In comparison operator which
allows you to define a condition with two or more
values within the Criteria box on the design grid.
In comparison operator
Allows the user to select records that match two or
more values.
Syntax
In("value","value","value")
Values can keep repeating.

Non-matching value
Selects records whose value for the selected
field does not match the simple condition.
Exactly the opposite of using the In operator.
Use this operator when looking for values that
are NOT within the set of values.
Syntax
Not In("value","value","value")
values can keep repeating. There is a space
between Not and In.

In Comparison Operator Example
Use the In comparison operator to find all students assigned
to the BUS and MGT programs.
Not In Comparison Operator Example
Use this operator to provide a listing of all customers
EXCEPT those that have been assigned customer numbers 123, 135 and 202.
Offered by the Center for Teaching and Learning @ UIS
Page 7 03/13/2000
Step 4 Type the question the prompt will ask in brackets.
Step 8 When query is run the parameter
box appears and asks the Criteria question.
Compound Conditions using AND and OR
The AND operator and OR operator are often combined to perform specific selections. The AND operator is used to only
select the records that meet all the criteria specified. If you want an AND condition, the criteria are entered on the same
line of the criteria box for each field with a criteria.
The OR operator is used to select records that meet one or all of the criteria specified. If you want an OR condition, the
criteria are entered on separate lines of the criteria box.
For example: "In order to meet the general ed requirements for English, the student must take Composition I AND
Composition II OR they must have passed the "Test Out" exam for English."
Parameter query
This type of query will plays its own dialog box prompting you for information every time it is run. It is important that the
value entered in the prompt box is typed and spelled just as it appears in the table. The item looked for is determined at
the time the query is run rather then when the query is designed. This allows for the "dynamic" nature in that the value
can be altered each time the query is run.
For example: you can create a monthly earnings query based on a parameter query. When you run the query a dialog box
appears asking for the month that you want the query to cover. You enter a month and Access displays the results in a
datasheet.
1. Begin a new query in design view.
2. Add the table whose records you want to query.
3. Drag the fields onto the design grid.
4. In the Criteria cell for each field you want to use as a parameter, type a prompt enclosed in square brackets.
Access will display this prompt when the query is run.
5. EXAMPLE: In the field for Program, which tracks the program for which a student is assigned, click in the criteria box
and type [For which Program do you want a list? ]
6. Switch to Datasheet view to see the results.
7. Close and save the query.
8. Double click on the query to run it, the parameter dialog box should appear with the Criteria Question!
Offered by the Center for Teaching and Learning @ UIS
Page 8 03/13/2000
Create the calculation using the buttons
and three columns below. This
calculation will display the current date.
EXPRESSION BUILDER
Parts of the Expression Builder
Top
In the upper section of the builder is an expression box
where you build the expression. Use the lower section of the
builder to create elements of the expression, and then paste
these elements into the expression box to form an
expression. You can also type parts of the expression
directly into the expression box.
Middle
In the middle section of the builder are buttons for commonly
used operators. If you click one of the operator buttons, the
Expression Builder inserts the operator at the insertion point
in the expression box.
Bottom
The three panes at the bottom of the Expression Builder
contain the Fields, Formulas and Functions you can use to
build a calculated field.
First Column
Contains folders that list the table, query, form, and report database objects, built-in and user-defined functions,
constants, operators, and common expressions.
Middle Column
Lists specific elements or categories of elements for the folder selected in the left box. For example, if you click
Built-In Functions in the left box, the middle box lists categories of Microsoft Access functions.
Third Column
Lists the values, if any, for the elements you select in the left and middle boxes. For example, if you click Built-In
Functions in the left box and a category of functions in the middle box, the right box lists all built-in functions in the
selected category.
Accessing the Expression Builder
Tables
While in Design View, click on a field that you want to create a calculation for, then click on either Default Value or
Validation Rule in the Properties section. The Expression Builder button will appear to the right.
Forms
Switch to Design View, then right click on an existing control or create a control. Select Properties, then the Data
Tab, then click with the Control Source box and you should see the Expression Builder button.
Queries
In Design View for the query, right click within the column for which you want to create a calculation, then click on
Build.
Offered by the Center for Teaching and Learning @ UIS
Page 9 03/13/2000
CREATING CALCULATED FIELDS IN QUERIES
There are many types of calculations you can perform in a query. For example, you can calculate the sum or average of
the values in one field, multiply the values in two fields, or calculate the date three months from the current date.
When you display the results of a calculation in a field, the results aren't actually stored in the underlying table. Instead,
Microsoft Access reruns the calculation each time you run the query so that the results are always based on the most
current data in the database. Therefore, you can't manually update the calculated results.
To display the results of a calculation in a field, you can use a predefined calculation that Microsoft Access provides or
custom calculations you define. Use the predefined calculations, called "totals," if you want to compute the following
amounts for groups of records or for all the records combined: sum, average, count, minimum, maximum, standard
deviation, or variance. You choose one totals calculation for each field you want to calculate.
Custom Calculation
Enter the expression for the calculated field in the Field cell in the query design grid.
1. Switch to Design View
2. Click in a blank column.
3. Right Click in the Field cell, select Build.
4. Use the expression builder to create a calculation.
Renaming the Calculated Field
In Design View, right click on the generic Expr# field name for the new calculated field, then click Properties, click inside
the Caption box and type the new field name. The new field name will not display in Design view, switch to Datasheet
view.
Using the Total Row to Create Calculations
1. In Design View click and drag the fields onto the
grid.
2. Click on the Totals button.
3. Click in the Totals box under each field name to
access the available command.
4. Click Run to see the results.
EXAMPLE: You want to see Total Amount of
Sale and Average Amount of Sale by Category
(Commodities or Contractual)
! For Category (Account) in the Total Row you
would use the Group By option.
! Under the first Amount of Sale use the Sum
option in the Total Row.
! Under the second Amount of Sale use the Avg
option in the Total Row.
! Click RUN and you would get the following
results.

Renaming the Field Name
When using the total row to
perform calculations the field
names in datasheet view will reflect the type of operation being performed. So, if the field is "summing all the amounts of
sale" then that fieldname will be called SumOfAmountOfSale. To rename the field something less cumbersome, do the
following,
1. In design view, right click in anywhere in the column that contains the field you want to rename.
2. Select Properties from the shortcut menu
3. Click next to caption and type a name.
4. Close the box and return to datasheet view.
Design grid - the current settings
in the Total Row for each field
will show Average and Totals
by Account (Commodities or
Contractual)

S-ar putea să vă placă și