Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
UPCOMING DEADLINES
• 21st October – MyITLab C (Today !)
• 1st November – Homework 4
(published)
• 4th November – MyITLab Lesson D
• 8th November – Homework 5
2
USING “LOOKUP” TYPE FIELDS
• Allow for clicking a drop down arrow
when entering field values to select
predefined items
• Eg:‘Year’ is a Lookup Type Field
• Two types of lookup fields:
1. Lookup references uses field values
in another table
2. Lookup references items you
manually enter in advance in the
same table
5
LOOKUP FROM OTHER TABLE
EXAMPLE
Create the third table for our database
called Countries
Make these fields:
ID AutoNumber (Primary Key)
Country Text
Flip to Datasheet view and save the tabl
6
LOOKUP FROM OTHER TABLE
EXAMPLE
Create the following Records:
1, England
2, America
Close the table
7
LOOKUP FROM OTHER TABLE
EXAMPLE
Return to the “Members” table in Design
View
Add a 5th field called Origin of type Lookup
Wizard
Use “I want the lookup column to look up
values in a table or query”
Select “Table: Countries
8
LOOKUP FROM OTHER TABLE
EXAMPLE
Add the Country field to Selected fields
Next… Next… Finish
Save if prompted
Return to Datasheet View in “Members”
Click in the Origin file to assign these:
Assign “England” to The Who members
Assign “America” to Van Halen members
9
SAME TABLE LOOKUP EXAMPLE
(LIKE STEP 5H)
In the Members table of our example, return
to Design View
Create a field called Instrument of type Look-
up Wizard…
Select I will type the values I want.
Enter the following:
Vocals, Drums, Guitar, Bass
Save, Return to Datasheet view to enter them
10
SAME TABLE LOOKUP EXAMPLE
(LIKE STEP 5H)
11
Members
BandNum FirstName LastName Origin Instrument
1 John Entwhistle England Bass
1 Pete Townsend England Guitar
1 Roger Daltry England Vocals
1 Kieth Moon England Drums
2 David Lee Roth America Vocals
2 Edward Van Halen America Guitar
2 Alex Van Halen America Drums
2 Michael Anthony America Bass
“YES/NO” FIELD TYPE EXAMPLE
Add a field called “Living”
Make it of Type Yes/No
Save the table and mark all records except
Keith Moon and John Entwhistle as Living
members
* We will come back to this
12
DATE FIELD EXAMPLE
• Add a field called Born of Date/Time
datatype
13
Members
Born
10/9/1944
8/23/1946
3/1/1944
5/19/1945
10/10/1954
1/26/1955
5/8/1953
6/20/1954
CREATE A RELATIONSHIP
EXAMPLE
Close the tables
Open Relationships
Note that lookup wizard created one already!
Right click, Show Table, add Bands.
Drag [Bands/BandNum] to [Members/BandNum]
Enforce referential, Create, and save.
14
QUERY EXAMPLE
• Show the names of the artists, their band
names, and their countries of origin
despite only having a band number in the
Member table and a lookup for country.
• We can use the relationship to seamlessly
query between fields in the three tables
and give the desired results…
15
QUERY EXAMPLE
• Create query in design view
• Add all tables (note the relationships showing)
• From Bands table double click to add: BandName
• From Members table add:
• FirstName, LastName, Instrument, Living
• From Countries table add: Country
• Run the Query ! • Close and Save Query as RockTrivia
16
18
LET’S TRY AN “AND”
Clear any existing criteria
Type England in the Country row and create the AND condition by placing Yes in the Living row to return all living band members from England
Run it
Go back and change Yes to No and rerun
19
LET’S DO AN “OR”
Remove the old criteria
We will set the criteria to show all
members from The Who OR anyone from
any band that is living at all from the list of
members…
First lets put “The Who” in the [Bands]
Name field and run to see the results
…
20
CREATE THE “OR”
• We wish to not only see the members of
The Who, but also in addition to them,
anyone that might be alive in the members
table.
In Design view, type “Yes” in the OR row
for [Members] Living
You should now see a list of 4 additional
records (8 total)
21
SORT EXERCISE
Open the RockTrivia Query in Design View
In the Sort row for the BandName field,
have it sort the records in Ascending Order
Run the Query
…
23
WILDCARD EXAMPLE
We want to see all members whose last names begin with “E”…
Remove all existing sort options
Make it read E* and run to get any other characters…
24
WILDCARDS CONTINUED
Change the criteria to show people whose
last names end in “N”
*N
Run it and we should see 3 records.
Remove all criteria.
25
CALCULATIONS IN A QUERY…
• Queries can be built to perform a calculation as part of the query
• We often do this for things that we do not need to store and take up space with
• Expressions can be entered into the query design grid as if they were regular fields
• Done on Numeric data type fields
26
CALCULATIONS IN A QUERY…
• To perform a calculation in a query, you must
add a calculated field to the query design.
• Make certain that you are following the rules
of precedence !
• Two options for entering expressions:
– Enter the expression directly into the field text box
– Enter the expression in the Expression Builder
27
CREATING A CALCULATED
FIELD
Remove the existing criteria
In design view, click in the next available
field, where the name would be, and then
click the magic wand “Builder” icon above.
The expression builder shows up…
29
LET’S MAKE A QUERY TO TRY
THIS…
Lets figure out how many years they have/would
been alive.
Build or type the following:
Age: (Date()-[Members]![Born])/365
Note: If you see <<expr>> be sure to remove it ! ! !
Run it !
Expand the width of the column if you see ####
30
CHANGING DECIMALS
PRECISION
In design view, right click Age field
Click Properties
Select Fixed for Format and 0 for Decimal
Places
Re-run it to see it without the decimal
places
FORMS & SUBFORMS
• You can create a form with a subform by including fields from each of two tables that have an established relationship formed
• When the relationship between the tables is a 1-many relationship, the main form will consist of data from the primary table and the subform will consist of data from the related table
31
FORM WITH SUBFORM
EXAMPLE
Create form by using wizard
Create ribbon > More Forms button > Form
Wizard
Click the “Tables/Queries” drop down and
select the Bands table, add BandName
32
FORM/SUBFORM CRITICAL
STEP!
• Switch to another table to add more fields!
Click the “Tables/Queries” drop down and
switch to the Members Table
Add: FN, LN, Origin, Instrument, and
Living
Click Next, and verify “Form with
subform(s)” is shown at the bottom
33
FORM WITH SUBFORM
EXAMPLE
Next > Select Tabular layout
Next > Select Flow style
Click Finish
Use the bottom navigation controls to
show the band up top and the members in
the bottom!
34