cis*1000*de – databases microsoft access (part 2)

34
CIS*1000*DE – Databases Microsoft Access (Part 2)

Upload: julianna-hamilton

Post on 25-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CIS*1000*DE – Databases Microsoft Access (Part 2)

CIS*1000*DE – DatabasesMicrosoft Access (Part 2)

Page 2: CIS*1000*DE – Databases Microsoft Access (Part 2)

(sigh)…Before We Get Started

• Last time we learned about Tables and Queries.• This time we’re going to learn about:

– The Expression Builder– Reports – But first we’re going to need some data, so…

• Download “example.mdb” from…http://www.uoguelph.ca/~jizhu/CIS1000DE/tutorials.shtml

• …and save it to the Desktop.

Page 3: CIS*1000*DE – Databases Microsoft Access (Part 2)

example.mdb

• Open up “example.mdb”

• This Database contains 2 Tables and 4 Queries:

People ID

Last NameAll Sales Made

Brand Name Sales

Minimum Age

Only Blue Eyes

QueriesPeople

First Name

Age

Birth Date

Eye Colour

SalesSale ID

Product Name

Brand Name

Price

Quantity

People ID

Page 4: CIS*1000*DE – Databases Microsoft Access (Part 2)

example.mdb cont’d

• The “All Sales Made” query…– Displays information about every single sale that’s been made.

• The “Brand Name Sales” query…– Displays the total number of each brand name item sold for

each type of product.

• The “Minimum Age” query…– Asks the user to input a minimum age and then displays the

people who are at least that age or older.

• The “Only Blue Eyes” query…– Only displays information about people who have blue eyes.

Page 5: CIS*1000*DE – Databases Microsoft Access (Part 2)

The Expression Builder

• Open up the “All Sales Made” query and switch into Design View.

• Take a look at the last two fields, “Price” & Quantity”• It stands to reason that if we know the price of an item

and how many were sold, then we could calculate the amount of revenue that was made.

(Price) x (Quantity) = Revenue• But how do we do this in MS Access? “Price” and

“Quantity” are two separate fields. How do we multiply them together to get the Revenue?

Page 6: CIS*1000*DE – Databases Microsoft Access (Part 2)

The Expression Builder cont’d

• The Solution? The Expression Builder!• To use the Expression Builder, we must first select an

empty field in our query in Design View.

• Now take a look at the Query Design Toolbar at the top of the screen and click on the Expression Builder button.

Page 7: CIS*1000*DE – Databases Microsoft Access (Part 2)

The Expression Builder cont’d

• You will get something that looks like this:

Page 8: CIS*1000*DE – Databases Microsoft Access (Part 2)

The Expression Builder cont’d

• Type in

“Revenue:”

The word “Revenue”will become the nameof the new field that

we are creating.

The Semicolon “:” is used to indicate the end of the FieldName and the beginning of

the Expression.

Page 9: CIS*1000*DE – Databases Microsoft Access (Part 2)

The Expression Builder cont’d

• Now, double-click on “Price” & “Quantity”

You should notice that those fields have now been added to our expression.

Page 10: CIS*1000*DE – Databases Microsoft Access (Part 2)

• Remove all the “<<Expr>>” that appear in b/t.• Add a “ * ” between [Price] and [Quantity].• Your finished expression should look like:

Revenue: [Price] * [Quantity]

• Click OK to get out of the Expression Builder.• Save the query (*this is important!)• View Datasheet View

The Expression Builder cont’d

Page 11: CIS*1000*DE – Databases Microsoft Access (Part 2)

The Expression Builder cont’d

Take note of the new column, Revenue.

Page 12: CIS*1000*DE – Databases Microsoft Access (Part 2)

Limiting the Query Results

• Now, what if we only wanted to know the five largest purchases that have been made?

• View Design View• Sort the query in Descending order

according to the “Revenue” field.• Now, take a look at the Design Query

Toolbar at the top of the screen and scroll-down and select “5” as the Top Value.

Page 13: CIS*1000*DE – Databases Microsoft Access (Part 2)

Limiting the Query Results cont’d

• Save the query.

• View Datasheet View

Notice how only the 5 largest sales are being displayed.

Page 14: CIS*1000*DE – Databases Microsoft Access (Part 2)

Other Built-In Functions

• MS Access contains many built-in functions.• For example, the “Month( )” function

extracts the month from a given date.• Similarly, the “Day( )” function extracts the

day from a given date, and the “Year( )” function extracts the year from a given date.

• To illustrate these examples, we’re going to create a new query that extracts the Month from a given Birth Date.

Page 15: CIS*1000*DE – Databases Microsoft Access (Part 2)

Other Built-In Functions cont’d

• Create a new query in Design View.

• Add the “People” table.

• Add the “First Name” & “Birth Date” fields.

• Click on an empty field and then click on the Expression Builder button.

• Type in,

Month: Month( )

Make sure that the cursor is in between the brackets.

Page 16: CIS*1000*DE – Databases Microsoft Access (Part 2)

Other Built-In Functions cont’d

• Double-click on the “Tables” folder, click on the “People” table, and then double-click on the “Birth Date” field.

• You should have an expression that looks like like this:

Month: Month([People]![Birth Date])

Page 17: CIS*1000*DE – Databases Microsoft Access (Part 2)

Other Built-In Functions cont’d

• Click OK to exit the Expression Builder.• Save the query.• View Datasheet View

Notice that the month that’s being displayed in “Month” field is the same as the month in the “Birth Date” field.

Page 18: CIS*1000*DE – Databases Microsoft Access (Part 2)

What’s a Report?

• A report presents the data in a table or query in an attractive fashion on the printed page.

• Reports are an effective way to present your data in a printed format.

• You have control over the size and appearance of everything on a report and you can display the information any way that you want to see it.

Page 19: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report

• Click on the Reports tab.

• We’re going to create a report using the “Wizard”

• Double-click on “Create report by using wizard”

Page 20: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report cont’d

• We’re going to create a report based on data from the “People” table.

• So, click and scroll - down until you find:

“Table: People”

Page 21: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report cont’d

• Add the “People ID”, “Last Name”, “First Name”, “Age”, & “Eye Color” fields by either double-clicking on them or by selecting them and then using the button.

Page 22: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report cont’d

• Click on Next.

• Double-click on “Last Name” to select it as our first grouping level.

Page 23: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report cont’d

• Click on Next.• This screen allows you to sort the data for the report.

Ascending Descending

• Sort the report in Descending Order According to Age

Page 24: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report cont’d

• Click on Next.• This screen allows you to select a default layout

and page orientation.• Select Stepped Layout.• Select Portrait Orientation.• Click on Next.

Page 25: CIS*1000*DE – Databases Microsoft Access (Part 2)

Creating a Report cont’d

• This screen allows you to choose a default style for your report.

• Select Formal.• Click on Next.• Name our report: “Personal Information”• Click on Finish. (A preview is presented in the next slide)• Now we can see what our report looks like. Yay! • But what if we’re not happy with the way it looks?

How can we edit the report? Design View

Page 26: CIS*1000*DE – Databases Microsoft Access (Part 2)
Page 27: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report – Design View

Page 28: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report – Design View cont’d

• Report Header – displayed only on the first page.

• Page Header – displayed at the top of each page.

• Last Name Header– formatting for the “Last Name” grouping level.

• Details – this section is printed repeatedly, once for each

row of data in the underlying table / query.

Page 29: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report – Design View cont’d

• Page Footer – displayed at the bottom of each page.

• Report Footer– displayed on only the last page.

Page 30: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report – Design View cont’d

• We can change the formatting and rearrange the fields.• Drag the textboxes around in the Page Header and in

the Details sections so that the “First Name” field is displayed first.

Page 31: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report – Design View cont’d

• You can change the appearance of each textbox. For example…

• Right-click on “People ID” in the Details section.

• Select Properties.

Page 32: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report – Design View cont’d

• Scroll down until you find Text Align. • Click on it, scroll down and select “Center”.

• This will center all the People ID numbers in the report.To verify that this worked simply switch back to Print

Preview.

Page 33: CIS*1000*DE – Databases Microsoft Access (Part 2)

Report - Design View cont’d

• Now, switch back into Design View.• Right-click on “People ID” in the Page Header

section and select Properties. • Change the Text Align to “Center”.• This will center the “People ID” page header name.• View Print Preview• Our report is now looking a little nicer / organized.So, in short, there are lots of properties that you can

play around with to manipulate the appearance of the report. Enjoy!

Page 34: CIS*1000*DE – Databases Microsoft Access (Part 2)

No More Access!

• As usual, if you have any questions, come to Zoe’s or John’s office hours or post a question to the online conferences.