You are on page 1of 174

Access 2007 & 2010:

Basic Database Development

OIT TECHNOLOGY TRAINING SERVICES

Access 2007 & 2010:


Basic Database Development

The University of Minnesota is an equal opportunity educator and employer. This publication/material is available in alternative formats upon request. Direct requests to oca@umn.edu. Printed on recycled and recyclable paper with at least 10 percent postconsumer material.

2011 Regents of the University of Minnesota. All rights reserved.

10.05.2011

Table of Contents
LESSON 1 I NT R O D UC T I O N T O DATABASES
Database Design Vocabulary Relationships Design Process

1 1
1 2 3

LESSON 4 C R E A T I NG R E L A T I O NS H I P S
Print the design Removing Tables from the Diagram Deleting or Editing Relationships

31 31
35 36 36

LESSON 5 LESSON 2 B UI L D I NG A D A T A B A S E I N ACCESS


Create an Access Database Set Access Options Creating Tables Exercise 1: Creating Tables Creating a Join Table

37 37
38

7 7
7 8 10 17 18

M OD I F Y I NG T A B L E S A N D R E L A T I O N S HI P S
Adding the New Foreign Key Field

LESSON 6 C R E A T I NG I NT E R F A C E S T O I NT E R A C T W I T H D A T A
Using Forms vs. Tables for data entry

41 41
41 42 49 55 64 71 73

LESSON 3

19

S E T T I NG F I E L D P R O P E R T I E S 19
Resizing text fields Input Masks Default values Format number fields Exercise 2: Setting field properties 20 21 24 26 28

Creating the Member Status type Entry Form Exercise 3: Creating Entry Forms Using Multiple Items Form Option Handling One-to-Many Relationships with Subforms Exercise 5: Creating a Subform using Autoform Linking the Main form and Sub Form Navigating Records and Entering Test Data

UNIVERSITY TECHNOLOGY TRAINING CENTER

Creating Forms using the wizard Exercise 6: Creating the CD entry form using the Wizard

74 79

LESSON 9 R E P OR T S
Creating a Report Using the Auto Report option

123 123
123

LESSON 6 CONTINUED
Adding to combo box lists on the fly Finding a Record on a Form Using a Combo Box to Find Records on the Form Creating the Member CD Form and Subform in Design View Date picker 84 86 89 93 101

Exercise 9: Creating a Report Using Auto Report 127 Creating a Report Using the Wizard Exercise 10: Creating a Report Using the Wizard 128 133

LESSON 10 F I N A L T O UC H E S
Menu

139 139
139 145

LESSON 7 E D I T I N G A F OR M
Modifying a Form

103 103
103

Database Maintenance and Backups

LESSON 8 Q UE R I E S
Creating a Query using the Query Wizard

107 107
107

Exercise 7: Creating a Query Using the Wizard 114 Adding Criteria to a Query Creating a Query in Design View Exercise 8: Creating a Query in Design View End of Exercise 116 118 121 122

UNIVERSITY TECHNOLOGY TRAINING CENTER

ii

LESSON 1: INTRODUCTION
TO

DATABASES

APPENDIX A U S I N G T H E L A B E L R E P OR T WIZARD

149 149

APPENDIX B C R E A T I NG A Q UE R Y U S I N G A GG R E G A T E F U N C T I O N S

153 153

APPENDIX C

157

E X P OR T I N G Q U E R Y R E S UL T S 157

APPENDIX D C R E A T I NG A M E M B E R ADDRESS REPORT USING


THE

161

WIZARD

161

APPENDIX E E X P OR T I N G A R E P O R T

165 165

UNIVERSITY TECHNOLOGY TRAINING CENTER

iii

1
Lesson
Less on 1

Introduction to Databases
Database Design Vocabulary
Database
Field: One piece of information you want to track in your database

Examples: Name or Birth Date or CD Title


Record: A group of fields containing data about one particular person, item, etc.

Examples: CD Title and Artist and Genre and Release Year


Table: A group of records

Example:
Table
TITLE The Best of Van Morrison Positive Friction Natural Sketches of Spain Kind of Blue Rice, Rice, Hillman and Pedersen Man of Constant Sorrow Sketches of Spain Man of Constant Sorrow I Wonder Where You Are Tonight A Day Without Rain In Pieces American Idiot GENRE Rock Americana Brazilian Jazz Jazz Bluegrass Bluegrass Jazz Bluegrass Bluegrass New Age Country Pop

Fields

PERFORMER Van Morrison Donna the Buffalo Celso Fonseca Miles Davis Miles Davis Rice, Rice, Hillman and Pedersen Ralph Stanley Miles Davis Ralph Stanley Del McCoury Enya Garth Brooks Green Day

YEAR 1990 2000 2003 1991 1991 1999 2001 1991 2001 2002 2004 2002 2004

OWNER Amy Jones Amy Jones Amy Jones Amy Jones Amy Jones Amy Jones Amy Jones Andy Jackson Andy Jackson Andy Jackson John Smith John Smith John Smith

Records

Example of a table in a flat/Excel file

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 1: INTRODUCTION
TO

DATABASES

Best Practice

When you expect multiple values or repeating data in a table, you should consider splitting the table into two or more related tables. For example, in the flat/Excel file shown above, Miles Davis is listed several times, as are some of the Genres and Owners.

Relationships

Relationship diagram showing the relationships between various tables

Types of Relationships
One-to-Many: The most common type. For every record in Table A, there are multiple

records in Table B Example: One Member may have many Addresses (work, home, etc.)
Many-to-Many: For every record in Table A, there are multiple records in Table B, and

vice versa. In this case, a third tablecalled a Join Tableneeds to be created, which will contain only unique values. Example: One Member may have many CDs, and the same CD (title) may be owned by many Members

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 1: INTRODUCTION
TO

DATABASES

Best Practice

The Join Table name should be a combination of the two many-to-many tables (e.g., tblMemberCD). The Primary Key can be the Join Table name or the first initial of each table name followed by ID (e.g., MemberCDID).
One-to-One: The rarest type, it is used for security and organization (i.e., avoiding empty

fields that only apply to some records in the table)

Keys
Key fields are used to build the relationships between data in different tables.
Primary Key: Auto-numbered, unique ID for internal tracking and for matching

records between related tables


Foreign Key: A number-type field in a related table pointing back to the Primary

Key in another table Best Practice

The Primary Key should be the table name plus ID (e.g., MemberID) and should be the same name in the table where it is used as a Foreign Key. (There are exceptions. In this course, the Foreign Keys LoanedToID and MemberID in tblMemberCD table both go back to the Primary Key MemberID in tblMember.) The Primary Key should always be the first field in each table, followed by any foreign key(s). Primary Keys should never be actual datanot even something unique like a Social Security number or Student ID. These values are obtained from an outside source and, while seemingly unique and reliable, could produce data entry errors.

Design Process
These preliminary steps are done on paper.

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 1: INTRODUCTION
TO

DATABASES

Statement of Purpose

Example: CD Club between friends: Database needs to catalog CDs owned by

each member and track the loaning of CDs between members. Classify all CDs by Genre, and list performer, year released, and value for each CD. Provide reports, such as member and CD listings. Best Practices

Use Prefixes in form or object names to denote different object types (e.g., tbl for tables). Avoid using spaces or special characters in object and field names. For single, repeating values requiring consistent data entry and searching, use a Lookup Table or Value List.
Value List: Works well for single, static, short lists of information that is

restricted to a list (e.g., Address Type). It is not easily updatable.


Lookup Table: Better for longer lists or those with multiple fields. It is easier to

add additional values at a later date. You can choose a level of restriction (e.g., Genre).

Determine Fields
Best Practice

Avoid multiple yes/no fields or fields that will be consistently left empty. Consider breaking out into a separate table or creating a Lookup Table of values to choose from. Keep items such as names (first name and last name) in separate fields. It is far easier to join those fields when needed than it is to separate a first name, last name, suffix, etc., to use in a mail merge or similar function. This also keeps them consistently in the same place. If you only have one field, you have little or no control over the order of entry.
4
UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 1: INTRODUCTION
TO

DATABASES

Consider an active/inactive status field instead of deleting records and losing history (such as Member Status).

Define Relationships

Refine and Test


Now is the time to review your design before you start creating your Access database. It is harder to make changes once you have data in the tables. Access is a database management system that also includes forms, queries, reports, etc. for ease of interacting with your data and extracting data from tables. Many other database systems (e.g., Microsoft SQL) require an interface be created in another program.
Forms: Queries: Reports:

Used for viewing, adding, and updating data Used to ask Access to return a selected portion of your data Used to format the data for printing

UNIVERSITY TECHNOLOGY TRAINING CENTER

2
Lesson
Less on 2

Building a Database in Access


Create an Access Database
The first step to creating an Access database is to create and name the database file that will store all of the tables, forms, etc. The file will be given a *.accdb extension automatically. Access databases must be named before they are used, because of the way Access saves data as it is entered. Anytime you open a database, an .laccdb file is created. The .laccdb file is used to store computer/user names and to control record-locking in shared databases. The .laccdb file always has the same name as the opened database and is located in the same folder. Whenever the last user closes the database, the .laccdb file is deleted.
1. Open Access

Go to Start Programs Microsoft Office Microsoft Office Access 2007 (or Microsoft Access 2010)

2. Name your database

In Access 2007, you may have to click Blank Database in the upper left corner first. In the window pane on the right hand side, type the name you want to give the database (in our case: CDClub).

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

1
2 4

Student\Desktop\Access 2010 Bas

3. Choose where you want to save the database

Click on the browse folder icon. Browse to and select your Desktop Access 2010 Basics folder

4. Then click Create. Access will open to a new table in datasheet view.

Access and Security


Access databases can contain harmful code. When you start a new database from scratch, that database could not possibly pose a security risk. However, any time you open a database in Access, you will have to let Access know whether the content is safe or not.

In Access 2007:

1. You will see a Security Warning just under the tools Ribbon. Click Options. 2. If you are absolutely positive the database is safe, choose Enable this content. If

you have any doubt, choose Help protect me from unknown content. This will turn off Macros that could potentially do harm to your database or computer.
3. Click OK

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

In Access 2010:
1. You will see a Security Warning just under the tools Ribbon. 2. If you are absolutely positive the database is safe, choose Enable this content. If

you have any doubt, simply close the warning with the small x on the right. This will turn off Macros that could potentially do harm to your database or computer. For more information about creating trusted locations for frequently used databases, and other security issues, search Access help for Security.

Set Access Options


Access 2010 gives us an initial table to work with in datasheet view. Before we start creating tables, there are a few settings to consider changing.
1. Open Access Options.

Click File (In 2007, Select the Office

button in the upper left corner).

Click Options (Access Options) at the bottom of the menu.

2. Change the default text field size.

Access 2007 has the default for text fields set at 255 instead of the old default of 50. That is much larger than needed for most fields and will eat up too much space. We will set this to a more reasonable 35. You only have to set this once, and it will apply for all future fields you create. It will not change older fields. Select Object Designers from the left hand pane. Change Default text field size: to 35.

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

3. Turn off Layout View

Access 2007 introduced a new view called Layout View. This view is a cross between Design View and Form View. It lets you make changes to the design while seeing data in the fields at the same time. This view can be confusing for new Access users, so we will disable it during class. Turning this view off or on only applies to the database you are currently working in. If you would like more information about the Layout View and when to use it, search Access Help for Layout View. Select Current Database from the left hand pane. Uncheck Enable Layout View for this Database

4. After the changes have been made click OK

Creating Tables
The first step in making a new Access database is to create all the tables we will need in our database. Access gives us an initial table to work with in datasheet view. It includes a primary key simply called ID. You want to give the primary key a more meaningful name so it is obvious

10

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

which table that ID belongs to. We will follow our best practice of naming the primary key as the table name followed by ID (with no spaces in the field name). Views in Access

For all objects we work with in this class, we will be switching back and forth between Design View of the object and the end user view or result (Data Sheet, Form, query results, or report results). The method of changing the view is identical.

Switch to Design View for the default blank table.


1. In the Table Tools Fields tab (2007: Table Tools Datasheet), click the View toggle button on the far left side of the ribbon.

2. Access will ask you to save the table first. Type in the table name tblMember.

3. Click OK

Table Design View


Design view for tables is used to create the table structure. On the left side is the Navigation pane that will show all of the tables, forms, queries and reports in the current database. On the right side is the design view of the table, in this case

UNIVERSITY TECHNOLOGY TRAINING CENTER

11

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

tblMember. The top section of the table Design View screen has three columns for entry

of Field Name, Data Type, and Description.

Navigation Pane

Table Design View

Design View of tblMember

Field Name Best Practices


Keep it short but meaningful. No spaces or special characters. Primary Key should be the table name plus ID (i.e., if the table is called tblAddress, the Primary Key should be AddressID). Add a DateCreated field to every table, which date stamps when the record was first entered. Avoid using keywords as field names (e.g., Date, Time, Now, Delete, User, Count, Value etc.). You can, however, have them as part of a field name (e.g., DateCreated). Access now will warn you if you enter a field name that is a key word.
UNIVERSITY TECHNOLOGY TRAINING CENTER

12

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

Data Type options


AutoNumber: Auto incrementing number used for Primary Keys. Number: Can contain only numeric values that you may need to use in calculations, also

used for all Foreign Keys.


Text: Allows for Alphanumeric data (letters, numbers, characters, etc.). Text is the

default data type. The default width is now 255, which is the maximum.
Memo: Alphanumeric Text field that allows for 65,535 characters. Use when you need a

very long note or description field.


Date/Time: Contains a date and/or time value. Dates are automatically validated against

the calendar. Date formats are determined by the Regional Settings on each PC. If those settings have been changed, you may get unexpected results.
Yes/No: Displays as a checkbox and stores one value (yes or no, true or false). Access

stores a No value as 0 and a Yes value as -1.


OLE Object: Used for storing files from other applications (documents, spreadsheets,

etc.). For more information on Data Types, search Access Help for Data Type in quotes (this restricts the search to that specific phrase, rather than searching for Data and Type separately).

Descriptions
The description is used to describe what a field is used for, and is entirely optional. This information will show up on a form as a screen tip if you hover over the field so it can also be used as tips for data entry.

UNIVERSITY TECHNOLOGY TRAINING CENTER

13

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

Add fields to a table


1. Enter the fields and their data types for tblMember. You can select the data type

by picking from the list, or you can just start typing the word and it will find and display the closest matching data type for you.

2. Once you have entered all the fields and their corresponding field types, close

and save the table design. You will be asked to confirm design changes on a table, form etc.

3. Click Yes 4. To create another table click on the Create tab on the Ribbon

14

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

5. Then Click Table

6. Switch to Design View

7. Save this table as tblMemberAddress

UNIVERSITY TECHNOLOGY TRAINING CENTER

15

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

Note:

Fields such as Zip and phone are created as text fields instead of number fields in order to apply input masks for controlling the data entry format (also in case you need to enter foreign Zip codes.)
8. Repeat for tblCD

Note: If you use Value instead of CDValue you would get the following message:

Click OK and correct the field name.

16

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

Exercise 1: Creating Tables


Create the following tables and save them as the table names given.
1. Create Tab Table 2. Switch to design view and create the following table:

3. Save and close tblGenre 4. Repeat for the following 2 tables:

End of Exercise

UNIVERSITY TECHNOLOGY TRAINING CENTER

17

LESSON 2: BUILDING
A

DATABASE

IN

ACCESS

Creating a Join Table


The Join Table is necessary for our many-to-many relationship. It has the usual Primary Key plus two Foreign Keys pointing back to the tables in the many-to-many relationship. It also contains another Foreign Key pointing to the Member table again, except this time it is tracking which Member the CD is loaned out to at the time. We cant use MemberID again so we will call it LoanedToID. A join table is created in the same way as any other table, using design view. Best Practice

The Join Table name should be a combination of the two many-to-many tables. The Primary Key can be the Join Table name or first initial of each table name followed by ID.

Note

When working with an existing database, you may or may not see some form of object-naming conventions and proper field/table names. Changing the names of tables and fields may affect many areas of your database, from relationships to forms and reports to possible VBA code behind the scenes. Use extreme caution when changing names if you are not sure where an object is used and how to correct errors that may surface after such a change.

18

UNIVERSITY TECHNOLOGY TRAINING CENTER

3
Lesson
Less on 3

Setting Field Properties


There are more options we can set besides data types on our fields. These options allow us to control or improve data entry such as limiting field sizes, adding formatting for phone numbers, or auto filling common values into fields. Best Practice

Set all the format properties and options at the table-level so they propagate through the forms, queries, and reports.

The General Tab


The bottom section of the Table Design View screen has two tabs. The General tab content varies based on the data type of the field currently selected. In the General tab, you can set field properties such as size, format, Input Mask, default value, etc. The Lookup tab is used for creating lookups for foreign key fields to the corresponding primary key.

General tab for a Text field

UNIVERSITY TECHNOLOGY TRAINING CENTER

19

LESSON 3: SETTING FIELD PROPERTIES

General tab for a Number field

Resizing text fields


The default number of characters for text fields in Access is now 255, which is the maximum for a text field. In most cases that is too large and will waste hard drive space. At the beginning of class we set that property to a more reasonable and space saving number of 35. That is still too large for some fields, and too small for a few others. You can also use the length of the field to control what is entered into the field. NOTE:

If you are working with a table that has data in it already, you may cut off existing data in that field if it is longer than the new field size you select. Access will display a warning message before it applies the change so you have a chance to cancel.
1. Open tblMemberAddress in Design View by right clicking on it and choosing Design View 2. Select the State field 3. Click on the Field Size value in the General tab 4. Change the value to 2

20

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 3: SETTING FIELD PROPERTIES

5. Repeat the same for the following fields:

Zip:

Field size of 9 (to allow for ZIP + 4)

Phone:

Field size of 10

Input Masks
Input Masks are used for consistent data entry and formatting of dates, phone numbers, and zip codes. Added characters (/ - ( ) , etc.) are for display onlythey are not saved as part of the data value. The field must be text, not numeric. If the Input Mask is added later, it will only show formatting correctly if it consists of straight numbers with no preexisting formatting. If you are working with existing data that has characters in the field (such as / or -), remove the extra charactersmanually or by using a Search/Replaceand the data will then correctly display with the chosen input mask.
1. Select the Phone field in tblMemberAddress 2. Click in the Input Mask field in the General tab.

UNIVERSITY TECHNOLOGY TRAINING CENTER

21

LESSON 3: SETTING FIELD PROPERTIES

The

(ellipses) button will appear to the right of the field

3. Click on the ellipses button to display the Input Mask Wizard 4. You will be asked to save changes made to the table design

5. Click Yes 6. The input mask wizard will appear. Choose the Phone Number option (first one

in the list)

22

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 3: SETTING FIELD PROPERTIES

7. In the Try It section, type in a phone number and see how it works.

Note:

With all Input Masks, if you tab into the field, the cursor will start at the beginning. If you click in the field, it will start wherever you click, and you have to move to the beginning of the field in order to type the data correctly into the Input Masks format.
8. When you are done testing the Input Mask, click Finish. This is what the phone

number input mask will look like in the general tab.

UNIVERSITY TECHNOLOGY TRAINING CENTER

23

LESSON 3: SETTING FIELD PROPERTIES

Default values
Default values can save data entry time for a field where most of the records entered will have the same value (i.e., most of the CD Club members will be from Minnesota). The value entered can be easily changed for the exceptions that occur. A default value will only be present in new records. Existing records will not be affected. In order for our DateCreated field in each table to work, we need to add a command into the default value. Default values apply only to new records. So every time there is a new record, we want to put in todays date automatically.
1. Select the State field in tblMemberAddress

2. In the Default Value field on the general tab, type MN

24

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 3: SETTING FIELD PROPERTIES

3. When you tab off the field it will put double quotes around the value.

4. Choose the Country field 5. In its default value type USA 6. Select the DateCreated field 7. In the Default Value field, type Date()

Note:

Be sure to include both parentheses! This will date stamp the creation of a new record when it is added to the table. If you wanted to be more precise, you could use the command Now(), which includes both date and time.

UNIVERSITY TECHNOLOGY TRAINING CENTER

25

LESSON 3: SETTING FIELD PROPERTIES

Format number fields


Integer (the default number type) does not allow decimal places and will automatically round up or down even if you specify it should have 2 decimals. If you need to have decimal places in a number value, you will need to use the Single or Double format depending on how large the number entered will be.
Byte: 0 to 255 (rounds up or down) Integer:

-32768 to 32767 (rounds up or down, default number type) Key auto number fields)

Long Integer: -2,147,483,648 to 2,147,483,647 (rounds up or down, default for Primary Single: Double:

-3.4x1038 to 3.4x1038 (up to 7 decimal places, will not round) -1.797x10308 to 1.797x10308 (up to 15 decimal places, will not round)

Prevent rounding of numbers with decimals


1. Open tblCD in Datasheet View by double clicking on the table name in the Object Navigation Pane on the left side

2. Type 14.99 in the CDValue field.

26

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 3: SETTING FIELD PROPERTIES

It will round up to 15 because by default it is an integer type.


3. Hit ESC to undo the data entry 4. Change to Design View of tblCD by clicking on the View toggle in the upper

left.
5. Click on the CDValue field to select it 6. Change the DataType to Currency

7. Switch back to Datasheet View and type in 14.99. It will now display as $14.99

and will not round.


8. Hit ESC to undo the data entry. 9. Close and Save the design changes to tblCD

UNIVERSITY TECHNOLOGY TRAINING CENTER

27

LESSON 3: SETTING FIELD PROPERTIES

Exercise 2: Setting field properties


Complete the formatting of the fields in Design View of the following tables:
1. In tblMember

Add the Date() command into the default value for DateCreated Add a Short Date Input Mask to the Birthday field

2. In tblAddressType

Add the Date() command into the default value for DateCreated

3. In tblMemberAddress

Apply the Zip Code mask to the Zip field

4. In tblGenre

Add the Date() command into the default value for DateCreated

5. In tblPerformer

Set Performer to a length of 100 Add the Date() command into the default value for DateCreated

6. In tblCD

Set Title to a length of 100 Add the Date() command into the default value for DateCreated

7. In tblMemberCD

Add a Short Date Input Mask to the DateOut field Add the Date() command into the default value for DateCreated

28

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 3: SETTING FIELD PROPERTIES

End of Exercise

UNIVERSITY TECHNOLOGY TRAINING CENTER

29

4
Lesson
Less on 4

Creating Relationships
In Access, you create the relationships between tableswhich youve previously defined on papervisually through the Relationship Window. Setting up the relationships here tells Access how the tables within this database are linked to each other. If you set up the relationships this way, the links between tables will carry through anytime you use the tables in a form, query, or report.
1. Click on the Database Tools Tab 2. Click on Relationships

UNIVERSITY TECHNOLOGY TRAINING CENTER

31

LESSON 4: CREATING RELATIONSHIPS

3. The Show Table dialog box will appear. Select all tables in the database at once

by holding down your shift key and click on the first table in the list, then the last table.

4. Click Add then click Close

Note:

If the Show Table dialog box is not open, you can right click in a blank section of the relationships window and choose Show Table

or use the Show Table button on the Design tab

5. Once you have all the tables showing in the window, you can rearrange them to

look like your paper diagram by simply dragging them around the window.

32

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 4: CREATING RELATIONSHIPS

Create the lines to connector relatethe Primary Keys to their respective Foreign Keys, as on our paper diagram.
6. Click on the Primary Key in one table and drag it over to the Foreign Key in the

related table. When you release the mouse you will see the Edit Relationships dialog box.

Verify you have selected the correct fields!

Important Notes!

These fields must be of the same data type to be related. If not, you will get an error message and will have to return to the table design and make the necessary corrections. Only one relationship is allowed between any two tables.

UNIVERSITY TECHNOLOGY TRAINING CENTER

33

LESSON 4: CREATING RELATIONSHIPS

7. Select Enforce Referential Integrity

On the Edit Relationships window, there is an option that should be checked for all tables: Enforce Referential Integrity, which prevents a record from being deleted in one table when there are related records in the other table. This option aids in data integrity by not allowing deletion of data creating orphan records. For example, you wouldnt want someone to delete a CD from the database that multiple people own and may be out on loan.

Note:

In Access 2003, setting Referential Integrity also acted as a required field setting. Setting Referential Integrity between Genre and CD, for example, will prevent you from adding a CD record without selecting a Genre as well. If you have data in the tables already, Access will not allow you to set Referential Integrity until all records meet this requirement. This was not the case before 2003 and has been changed back in 2007 so that it does not create the required field property.
8. Click Create 9. Repeat for all tables in the database

34

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 4: CREATING RELATIONSHIPS

10. Close and save your relationship design

Print the design


You can print out the design to reference as you are working on the database, to keep track of changes made or to present to a manager or end user.
1. Return to the relationships window using the Database Tools tab.

2.

Select the Relationship Report

3. Switch to Landscape layout

UNIVERSITY TECHNOLOGY TRAINING CENTER

35

LESSON 4: CREATING RELATIONSHIPS

4. After you have printed the report close the report preview window using the X in

the upper right hand corner.

5. Choose No when it asks to save the report.

Removing Tables from the Diagram


If you accidentally add a table to the window more than once, it will add the table again and name it [tablename]_1. To remove the extra table, just select the table and hit Delete. (You are not deleting anything from the database itself.)

Deleting or Editing Relationships


Double click on the relationship line drawn between two tables to edit the relationship. Right clicking on the line will also give you the Edit option, as well as the option to delete the relationship. Removing a table from the relationships diagram that has a relationship link to another table will not remove the relationship itself. To completely remove the relationship, you have to delete the relationship before you remove the table from the diagram.

36

UNIVERSITY TECHNOLOGY TRAINING CENTER

5
Lesson
Less on 5

Modifying Tables and Relationships


Often in the process of creating the tables and relationships, in the refine and test stage, you may find that you need to rethink part of your design. Its a good idea to consider having a status field in your main table of the database (in our case tblMember). The primary reason is after a while the number of records in the table will increase, all those records in a drop down or a form could slow things down. If you only want to show current members you can filter out anyone else and shorten up that list again, rather than deleting the inactive members and losing the history.
1. Open CDClub.accdb from your desktop 2. Click on the Create tab

3. Then click Table

UNIVERSITY TECHNOLOGY TRAINING CENTER

37

LESSON 5: MODIFYING TABLES


AND

RELATIONSHIPS

4. Switch to design view 5. Create the fields as shown below:

6. Edit field properties

Add the Date() command into the default value for DateCreated

7. Close and Save the table design

Adding the New Foreign Key Field


1. Add the new foreign key field MemberStatusID to tblMember

Open tblMember in design view by right clicking on the table name in the navigation pane

Right click on the DateCreated row and choose Insert Rows

38

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 5: MODIFYING TABLES


AND

RELATIONSHIPS

Add MemberStatusID as a Number type in the new row

2. Edit the Relationships

Under Database Tools, select Relationships


Add the new table (tblMemberStatus) to the Relationship Window using the Show Table dialog box Link tblMemberStatus to tblMember using the MemberStatusID field Set Referential Integrity
Close and Save

the relationship design changes

Updated Relationships

UNIVERSITY TECHNOLOGY TRAINING CENTER

39

6
Lesson
Less on 6

Creating Interfaces to Interact with Data


Using Forms vs. Tables for data entry
Once you have your tables created and relationships set, you can move on to creating the forms. Forms are used to enter, view and edit data in the tables. You should not enter data directly into the tables themselves. Regardless of if it is a database you created, one that has been purchased, or one set up by someone else. All database programs can have data integrity issues caused by adding, editing, or (worst case scenario) deleting information in a table. Tables are meant to be behind the scenes, not directly interacted with. Dont think of the tables as Excel spreadsheets. They are the backbone of your database and should not be used for data entry. Software programs containing a database backend will usually not even allow you access to the tables. All interactions with the data are done through forms and queries. Often forms in an Access database have additional calculations or automation code within them that will not run if data is entered into a table directly. Forms will also keep track of all the Primary and Foreign Key relationships for you. An end user would have a hard time knowing what key value a particular field in a related table has. Access is more suited to managing the tables and keys itself.

Example of a table with multiple foreign keys after data is entered through a form.

UNIVERSITY TECHNOLOGY TRAINING CENTER

41

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

We will examine 4 methods for creating forms in Access 2007 along with the ability to update the values in a lookup table on the fly when doing data entry on a form.

Creating the Member Status type Entry Form


From this point use the cdclubTables database from our class files folder.
1. In the object navigation pane, click on tblMemberStatus (the table name that is

currently highlighted will be used for the source of the form).


2. Select the Create tab 3.

In the Forms section, select the Multiple Items icon

Types of Forms
Single/Columnar Form: Displays one record at a time. Multiple Item/Continuous/Tabular Form: Displays as many records as will

fit in the detail section of the form. As you type in one record, a new record is started below. The multiple items form is most often used for the lookup tables to create an easy form to maintain the values in those tables.

This method of form creation automatically selects all fields from the table and displays them on the form in Form View.

42

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

4. At this point the basic form is ready for data entry. Enter the following values:

Active Inactive

Note how the icon to the left changes to a Pencil symbol and a new record is created below as soon as you start typing in the Member Status field. The primary key ID is also assigned at this point. The Pencil means this record is currently being edited. Once you leave that record, it is automatically saved, and it moves to the next record.
5. Make note of what MemberStatusID number gets assigned to Active, we will

need that later in this exercise.


6. We can edit this form in design view by selecting the Home tab, then using the

view toggle button.

Design view of a form

When you open the form in design view initially it may show all the fields and labels with an orange border. This means they are currently grouped together. To ungroup them, click anywhere in the form outside of the grouping.

UNIVERSITY TECHNOLOGY TRAINING CENTER

43

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

7. Edit the form title in the form header by clicking once to select the field, then

clicking again on the text of the field to go into edit mode. Remove tbl and put a space between Member and Status

8. Remove the MemberStatusID field. This field does not need to be shown on the

form. Select the field and hit Delete on your keyboard.

Access automatically repositions the other fields after you remove a field. 9. Put spaces in the field names to separate the individual words in the labels that are

in the header section.

44

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Important Note!

You can edit the label (the transparent box), but you cannot edit the text box (the white box). The text box is the actual field name that the data entered will be saved into. If you change or delete the content in the white box, Access will not know where to save the data entered on the form. If you do accidentally change the field name, Access 2003 and later will mark the field and give you suggestions to fix the error. For example, if you change the MemberStatus field to Member Status, the field will show a green triangle in the upper left corner.

Click on the triangle to produce a yellow exclamation sign. Click on it to see the Access tips for fixing the problem.

The highlighted fields are the applicable errors. Listed below are possible solutions. In this case, the solution would be to Edit the Controls Control Source

UNIVERSITY TECHNOLOGY TRAINING CENTER

45

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Property and choose the correct field (or simply remove the space so it is a valid field name).

Locking the Field


Because the Date Created is automatically filled in, and we would not want someone to accidentally or purposely change it, we will lock that field from being edited.
1. Right click on the DateCreated Field in the detail section of the form and choose Properties OR double click on the field 2. On the Property Sheet Data tab change Enabled to No and Locked to Yes

Note about Enabled and Locked Properties

The Enabled and Locked properties can be used together or independently depending on the desired outcome.
Enabled=No

will lock and grey out the field

Locked = Yes will lock the field but not grey it out. The field is selectable and

can be copied. It can cause confusion on the end users part because it acts like one should be able to type in the field
Enabled=No AND Locked = Yes

will lock the field but not grey it out

and not allow a cursor into the field.

46

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

3. Return to form view using the View toggle to see the changes made. 4. Close and Save the form as frmMemberStatus

Setting Active as the default Member Status


If we want all new members to automatically be assigned an Activestatus we can set the default property in the MemberStatusID field in tblMember.
1. Open tblMember in design view 2. Select the MemberStatusID field 3. In the General tab, under Default Value, type in the number we wrote down

earlier as being assigned to the Active status.

4. Close and save tblMember

UNIVERSITY TECHNOLOGY TRAINING CENTER

47

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

48

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Exercise 3: Creating Entry Forms Using Multiple Items Form Option


Part 1:
Performer entry form: We need to enter the performers ahead of time in order for

them to show up in combo box used to create a CD record. This form is used to add and edit the values in tblPerformer.

1.

In the Object Navigation pane, click on tblPerformer

2. From the ribbon menu choose Create

UNIVERSITY TECHNOLOGY TRAINING CENTER

49

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

3. From the Forms section choose Multiple Items

4. Switch to Design View using the View Toggle on the Home tab 5. Edit the Label in the header of the form to remove the tbl 6. Delete the PerformerID field 7. Put spaces in the DateCreated label 8. Lock down the DateCreated field using the field properties (set Enabled to No

and Locked to Yes)

9. Save and name the form as frmPerformer 10. Switch to Form View and enter test data:

Enya Garth Brooks Green Day

50

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Ludwig van Beethoven Ralph Stanley

UNIVERSITY TECHNOLOGY TRAINING CENTER

51

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Part 2:
Address Type entry form: We need to enter the Address Types ahead of time in order

for them to show up in combo box used to create an Address record. This form is used to add and edit the values in tblAddressType.

1. In the Object Navigation pane, click on tblAddressType 2. From the ribbon menu choose Create 3. From the Forms section choose Multiple Items

4. Switch to Design View using the View Toggle on the Home ribbon menu 5. Edit the Label in the header of the form to remove the tbl and put a space

between address and type


6. Delete the AddressTypeID field 7. Put appropriate spaces in the AddressType and DateCreated labels

52

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

8. Lock down the DateCreated field using the field properties (set Enabled to No

and Locked to Yes)

9. Save and name the form frmAddressT ype 10. Switch to Form View and enter test data:

Home Work School

End of Exercise
53

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

54

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Handling One-to-Many Relationships with Subforms


A subform is a form within another form. A form-to-subform relationship can be defined as a parent/child relationship. A subform is the best method of showing records from the table on the many side of the one-to-many relationship. For the record currently displayed in the main form, many records can be shown on the subform. One example of this in our database is the members and their addresses. We opted to allow multiple addresses for each member. The main form shows one member from the member table, while the subform displays all of the address in the member address table associated with that members ID. Create a form to enter members with a subform to enter multiple addresses for each member.

Member Form
The member form is the main form that shows one member record at a time.

1. In the object navigation pane select tblMember 2. Choose the Create tab

UNIVERSITY TECHNOLOGY TRAINING CENTER

55

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

3. Under the Forms section choose Form

Newly created member form 4. Go to the Home tab and Switch to Design View

frmMember in Design View

56

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

5. Click outside the field grouping to ungroup them 6. Edit the top label in the header to read Members instead of tblMember 7. Edit the field labels to add spaces between the words

Put a space between Member and ID

We wont delete the key field in this case since the MemberID could be referenced and searched by within the database (like an account number)


8.

Put spaces between First, Middle, and Last and Name Put a space between Date and Created

Replace MemberStatusID with a combo box that looks up the values from tblMemberStatus Select the MemberStatusID field and click delete From the Design Tab click on the Combo Box object to select it (it will place an orange border around the selected object).

Move your mouse to the location on the form that you want to place the object, in this case - below the Date Created field. (Your mouse icon will change to the icon for the object you have selected).

UNIVERSITY TECHNOLOGY TRAINING CENTER

57

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

The combo box wizard will appear, leave the default option, click Next

Select tblMemberStatus and click Next

Move MemberStatusID and MemberStatus fields into the selected fields area by double clicking or using the > button, click next.

58

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Note: When creating a combo box the Primary Key of the lookup table should always be the first field and the text field the user will actually see and pick from should be the second field. Select MemberStatus as the field to sort by, click next

The next screen is a preview of what the drop down box contents will be. Here you can make the column(s) wider or narrower as needed. Note that the Primary key (the first field we selected) is automatically hidden from the user.

UNIVERSITY TECHNOLOGY TRAINING CENTER

59

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

This step is critical, we must tell Access where to store the selection we make. The combo box stores the value of the primary key which needs to be saved to the corresponding foreign key in the table the form is based on. Use the dropdown to select the matching foreign key field MemberStatusID, click next.

Type in the text you want for the label part of the combo box: Member Status, click Finish

60

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

9.

Move the newly created combo box below the Birthday field. Access will automatically move the DateCreated field down to accommodate for it and reformat the field to match the others. need to shorten the fields to make room to add a subform. Group all of the fields in the detail section

10. We

Click anywhere above the MemberID Field (not the label, we dont want the labels included in this grouping)
Drag your mouse down and to the right until all fields are within the box it has created.

UNIVERSITY TECHNOLOGY TRAINING CENTER

61

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

11. Let

go of the mouse and all the fields will be grouped and showing the orange border

Make sure that the labels to the left of the fields are not included in the grouping (not outlined in orange) 12. Hover over

the right side and get the double arrow, then drag the group to the left to shorten all the fields at once.

13. Release

your mouse around the 4 inch mark

14. Lock

down the DateCreated field by setting enabled to no and locked to yes in the fields properties

62

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

15. Close and Save the form as frmMember

UNIVERSITY TECHNOLOGY TRAINING CENTER

63

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Exercise 5: Creating a Subform using Autoform


Member Address Subform
Used to enter multiple addresses for a member once it is connected to the member form.

1. In the object navigation pane select tblMemberAddress 2. Choose the Create tab 3. Under the Forms section choose Form

64

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

4. Go to the Home ribbon menu and Switch to Design View 5. Click outside the field grouping to ungroup them 6. Edit the top label in the header to read Addresses instead of tblMemberAddress 7. Delete the MemberAddressID and MemberID fields 8. Replace the AddressTypeID with a combo box

Delete the AddressTypeID field Select the Combo Box option from the design tab and place it under date created on the form Select tblAddressType Select AddressTypeID and AddressType

Sort by AddressType Store the value in AddressTypeID

UNIVERSITY TECHNOLOGY TRAINING CENTER

65

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Type Address Type for the label text Move the newly created combo box above the Address1 field.

9. Edit the field labels to add spaces between the words

Put spaces between Address and the 1, 2 or 3 Put a space between Date and Created

10. Group

all of the fields in the detail section

Click anywhere above the AddressTypeID Field (not the label, we dont want the labels included in this grouping)
Drag your mouse down and to the right until all fields are within the box it has created.

11. Let

go of the mouse and all the fields will be grouped and showing the orange border

Make sure that the labels to the left of the fields are not included in the grouping (not outlined in orange)

66

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

12. Hover over

the right side and get the double arrow, then drag the group to the left to shorten all the fields at once.

Release your mouse around the 3 inch mark

UNIVERSITY TECHNOLOGY TRAINING CENTER

67

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

13. Because this is a subform, we want it to be compact. We also need to shrink the

size of the form itself (the area with the grid behind it). You may have to scroll to the right to see the edge of the form.

14. Hover over the right edge of the form and get the double arrow with the vertical

line.
15. Drag the side of the form up to the right edge of the fields and release.

Oops! It didnt work. The box for the addresses label is very large and needs to be shrunk as well.

68

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

16. The

easiest way to do that is to right click on the Addresses label in the header and choose Size To Fit

17. Then repeat step 13.

UNIVERSITY TECHNOLOGY TRAINING CENTER

69

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

18. Lock

down the DateCreated field by setting enabled to no and locked to yes in the fields properties

19. Close and Save the form as subfrmMemberAddress (use the subfrm

prefex for all sub forms)

Note:

You should not enter an address in the subform as it is right now. You need to have it linked to the main form first to know what member the address belongs to. We will do that in the next step together.

End of Exercise

70

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Linking the Main form and Sub Form

This step is similar to setting the relationship between two tables. We need to tell Access which primary key/foreign key fields link the two forms. This method also allows Access to maintain the Primary and Foreign Key values that are used to match the addresses with their respective members.
1. Open frmMember in Design View 2. In the Design tab in the Controls section click on Subform/Subreport

3. Click in the detail area to the right of MemberID 4. From the subform wizard click on Use an Existing Form

UNIVERSITY TECHNOLOGY TRAINING CENTER

71

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

5. Choose the subfrmMemberAddress form Click Next

6. In the Define Link form, choose the Show tblMemberAddress for each record in tblMember using MemberID option Click Next

If the show statement is cut off in the selection window you can see the full statement right below.

72

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

7. Leave the name subfrmMemberAddress for the form name Click Finish

8. Select the subfrmMemberAddress text box created as a title for the

subform and press Delete on your keyboard.

9. Save the design changes to form. 10. Switch to Form view

Navigating Records and Entering Test Data


Navigating Records
To move between records, use the navigation bar at the bottom of the form.

First Previous Next Last

UNIVERSITY TECHNOLOGY TRAINING CENTER

73

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

New Record When you have a subform you will have a second set of navigation buttons to move through the subform records.

1=Main form, 2=Subform

Entering Test Data


1. Enter in your name and birth date in the main section of the Member form 2. In the addresses subform, choose Home as the address type and enter in your

home address
3. Click on the Next button in the subforms navigation bar 4. Choose Work or School as the address type and enter another address for

yourself
5. Click on the Next button of the main Members form and repeat for another

member. Enter a friend, relative, or made up member with two different addresses

Creating Forms using the wizard


Genre Form

This form will be used to enter values into the Genre Lookup Table for use when entering CDs.
1. On the Create ribbon menu choose More Forms Form Wizard

74

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

2. Choose tblGenre from the dropdown list

3. Select the fields that you want to see on the form by using the > button.

In this case we want Genre and DateCreated

UNIVERSITY TECHNOLOGY TRAINING CENTER

75

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

4. After the 2 fields are under the Selected Fields area, click Next 5. Choose the Tabular option (multiple items/continuous type of form), click Next

76

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

6. To make this form match our previously created forms choose the Access 2007

style, click Next

7. Name the form frmGenre and click Finish

8. From the Home menu, switch to Design View 9. Remove frm from the frmGenre label 10. Widen the Genre field and label 11. Lock

down the DateCreated field by setting enabled to no and locked to yes in the fields properties

12. Save the design changes and switch back to Form view

UNIVERSITY TECHNOLOGY TRAINING CENTER

77

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Modify Formatting
1. Enter test data:

Country Rock Pop New Age Jazz Classical

Note the Alternating lines created with this style of creating a form.
2. If we want to turn that off to match the style of the other forms we have created,

go to design view and right click on the detail section bar

78

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

3. Hover over Alternate Fill/Back Color and select None to remove it.

Exercise 6: Creating the CD entry form using the Wizard

1. On the Create tab choose More Forms Form Wizard

UNIVERSITY TECHNOLOGY TRAINING CENTER

79

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

2. Choose tblCD from the dropdown list

3. Select the fields that you want to see on the form by using the > button.

PerformerID GenreID Title YearReleased CDValue DateCreated

4. After the desired fields are under the Selected Fields area, click Next 5. Choose the (default) Columnar option (Single form), click Next

80

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

6. To make this form match our previously created forms choose the Access 2007

style, click Next

UNIVERSITY TECHNOLOGY TRAINING CENTER

81

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

7. Name the form frmCD and click Finish

8.

From the Home tab, switch to design view

9. Remove frm from the frmCD label 10. Remove the PerformerID field and replace with a combo box

Select PerformerID and Performer from tblPerformer Sort by Performer Save selection to the PerformerID field Label as Performer

11. Remove the GenreID field and replace with a combo box

Select GenreID and Genre from tblGenre Sort by Genre Store the selection in GenreID Label as Genre

12. Space out the words in CDValue, YearReleased and DateCreated labels 13. Lock

down the DateCreated field by setting enabled to no and locked to yes in the fields properties

82

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

14. If you want to have the fields in a different order (more logical for data entry),

simply drag them up or down in design view. Move the title field to the top, followed by Performer, Genre, Year Released, Value and Date Created

The other fields automatically adjust for you.


15. Shorten

all fields and the form itself so it is more compact but still has room in the fields for the data.

16. Close and save the form

End of Exercise

UNIVERSITY TECHNOLOGY TRAINING CENTER

83

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Adding to combo box lists on the fly


1. Enter test data into frmCD: Title A Day Without Rain American Idiot Beethoven's Greatest Hits I Wonder Where You Are Tonight In Pieces Kind of Blue Man of Constant Sorrow Performer Enya Green Day Ludwig van Beethoven Del McCoury Garth Brooks Miles Davis Ralph Stanley Genre New Age Pop Classical Bluegrass Country Jazz Bluegrass Year 2004 2004 1984 2002 2002 1991 2001 Value $ 15.00 $ 16.00 $ 12.00 $ 15.00 $ 15.00 $ 15.00 $ 15.00

What happens if the Genre or Performer does not exist in the Combo Box?
Answer:

Starting with Access 2007 you will be prompted about adding the new value to the list

Click Yes and the form you specified in the field properties will open up and you can go to a

84

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

new record and add the missing value. The value will be immediately available for use in the main form once you close the edit form.

2. When you get to the first missing Performer (Del McCoury), hit esc a couple times

to clear out the data entry


3. Switch to design view 4. Right click on the PerformerID field and choose Properties 5. On the Data tab under List Items Edit Form choose frmPerformer from the

drop down list

6. Close the properties window 7. Repeat for the GenreID field, choosing frmGenre 8. Continue with the data entry 9. Close and save the form

UNIVERSITY TECHNOLOGY TRAINING CENTER

85

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Finding a Record on a Form


You can move through the records using the navigation bar at the bottom of the form in a small record set. Once you have a large amount of records, however, it is tedious to go through them one by one to find the record you need. There are a number of ways to quickly locate a record or subset of records on your form. Searching, filtering and using a search combo box will be examined.

Quick Search
1. Open frmCD in Form View 2. Click in the search box in the bottom navigation bar 3. Start typing in a word that appears in any field on any record in the form. As you

type the word the first record that has a match will be displayed. Ex. Where, or blue. Hit enter to move to the next matching record if there are more.

86

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Filtering by Selection
1. Locate a record that has a Bluegrass CD 2. Place your cursor in the Genre field 3. On the Home tab, in the Sort and Filter section, click on Selection 4. Options will be displayed that will help you choose how to filter. Choose the Equals Bluegrass option

5. The form will show that it is Filtered and how many records it found that matches

the filter in the navigation area at the bottom of the form

The form now only shows the 2 records that have a bluegrass Genre type.
6. To remove the filter and see all records again click on Filtered and it will change

back to Unfiltered

UNIVERSITY TECHNOLOGY TRAINING CENTER

87

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Filtering by multiple items


1. Click in the Genre Field 2. Choose Filter from the Sort and Filter section

A Popup will display all the options for that field 3. Clear all check boxes by unchecking the Select All option 4. Select only Bluegrass and Jazz

5. Click OK

The records showing will be anything with Bluegrass OR Jazz genre types.
6. To remove the filter, click on Filtered in the navigation area at the bottom of the

form and it will change back to Unfiltered.

88

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Using a Combo Box to Find Records on the Form


If you want something more permanent and fewer steps than a filter, you can add a Combo Box that will find a single record on the form for you. The Combo Box can also be used to help avoid duplication of entries if you check existing values before adding a new record.

7.

Open frmCD in Design View

8. From the Design menu Controls section click on the Combo box icon

9. Click in the form header section next to the CD label (leave enough room for the

combo box label in between)


10. From the Combo Box wizard, choose the third option Find a record on my form based on the value selected in my combo box Click Next

UNIVERSITY TECHNOLOGY TRAINING CENTER

89

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

11. Add the CDID, Title, and Year Released fields to the Selected fields

window Click Next

12. Expand the Title field Click Next

90

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

13. Name the Combo Box Find CD Click Finish

14. Use the Font Size and Bold options on the toolbar to make the Find CD label Bold

and 14 point
15. Expand the width of the Combo Box and the label

16. Switch to Form View and test the combo (lookup) box 17. The list currently is not sorted, to make this function work better we need to sort

by the CD Title (the field you would be typing a value for) Switch back to Design View Right click on the combo box and choose Properties On the Data Tab click in the Row Source field Click on the Ellipsis button at the end of the field

UNIVERSITY TECHNOLOGY TRAINING CENTER

91

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Choose Ascending in the sort row under Title Close and Save the Query

18. Switch to form view and search for a CD by typing in the start of a Title or drop the

list down and make a selection


19. Save and close the form

92

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Creating the Member CD Form and Subform in Design View


We will create the form and subform to track each members list of CDs that they own, and the loaning of those CDs to other members, from scratch using design view.

Creating the Member CD Main Form


1.

From the Create tab, in the forms section choose Form Design

UNIVERSITY TECHNOLOGY TRAINING CENTER

93

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

2.

Click on Property Sheet

3.

On the Data Tab, use the drop down for Record Source to choose tblMember (the table this form needs to be based on)

4. 5.

Close the Property Sheet From the Tools section choose Add Existing Fields

94

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

The field list is divided into 3 sections: Fields from the table you chose as the record source, fields from tables related directly to that table and the rest of the tables in the database. You can change the view to only show fields from the table you selected by clicking on at the bottom of the field list.

UNIVERSITY TECHNOLOGY TRAINING CENTER

95

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

If you select records from a table other than your record source it will change to the record source to a query joining the appropriate tables. This may produce undesired results. You can return to seeing all tables by clicking on Show all tables at the bottom of the field list.
6.

Select the FirstName field and drag it onto the form

7.

Drag LastName onto the form to the right of FirstName

8.

Put spaces in the labels between the words

96

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

9. Close and Save the form as frmMemberCD (you will come back to it later

to add a subform)

Creating the Member CD Subform


This form allows for all the CD titles owned by the member in the main form to be displayed or added to. It is also used to show if a CD is currently out on loan, to whom and when it was loaned out.
1.

From the Create menu ribbon, in the forms section choose Form
Design

2.

From the Property Sheet choose tblMemberCD as the Record Source

3. Create a Combo Box for the CD selection

Base the combo box on tblCD Select the fields CDID, Title and YearReleased (in that order) Sort by Title Save the selection to the field CDID Label as CD Widen the field

UNIVERSITY TECHNOLOGY TRAINING CENTER

97

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

4. Create a combo box for the Loaned To field to the right of the CD field

Base the combo box on tblMember Select the fields MemberID, LastName and FirstName (in that order) Sort by LastName Save the selection to the field LoanedToID Label as Loaned To

5. Click on Add Existing Fields

Drag the DateOut field from the field list to the right of the Loaned To field

6. Change the form to a Continuous Form (multiple item type of form)

Click on the Property Sheet in the tools section Make sure the drop down says Form, if it is anything else change it to Form

Switch to the Format Tab Use the dropdown to change the default view from Single Form to
Continuous Forms

98

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

7. Close the properties window 8. Shrink the form up from the bottom so it is just bigger than the fields (or it will

leave a lot of white space in between each record)

9. Close and save as subfrmMemberCD

Link the main form to the subform


1. Open frmMemberCD in design view 2. Add subfrmMemberCD using the Subform option from the Controls

3. In the subform Wizard, choose the existing form subfrmMemberCD 4. Link the form and subform by the common key field MemberID 5. Finish the subform wizard 6. Back at the form design view, delete the label above the subform 7. Expand the border of the subform downward to make room to show multiple

records

UNIVERSITY TECHNOLOGY TRAINING CENTER

99

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

8. Save the design changes and switch to form view 9. Use the MemberCD form to loan a CD to another member in the club,

including filling in the Date Out field. (If there are no other members listed in the Loaned to dropdown, add another member through the Member form.) Did you notice?

We chose two fields for the Loaned To Combo Box, but only one showed up after you chose the member. When you drop down the item, you will see all the fields, but only the first field after the Primary Key ID will display once selected. If you would rather see the first name instead of the last, recreate the Combo Box, choosing the Primary Key first and then FirstName followed by LastName.

100

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 6: CREATING INTERFACES


TO

INTERACT

WITH

DATA

Date picker
The date picker is a new feature to Access 2007, it is a popup calendar you can use to enter a date into a field instead of manually typing in the numbers. The icon will show on forms and reports next to a date field currently being edited. It also has a handy Today button at the bottom to easily select the current date.

The Date Picker will not be available if there is an input mask on the date field. That is the case with our Date Out field. If we want to use the calendar to select a date for this field we have to go back to the table and remove the Input mask from the field.
1. Open tblMemberCD in design view 2. Select the DateOut field 3. On the General tab, clear out the value in the Input Mask 4. Close and save the table design changes 5. Try it out on the form

UNIVERSITY TECHNOLOGY TRAINING CENTER

101

7
Lesson
Less on 7

Editing a Form
The Member CD form and subform we created in design view do not match the style of the forms we created using the automated tools. We can edit that form and assign a format to it and add a label in the header.

Modifying a Form
1. Open frmMemberCD in Design View 2. Go to the Arrange tab 3. In the Show/Hide section choose Form Header/Footer

New form header section has been added

UNIVERSITY TECHNOLOGY TRAINING CENTER

103

LESSON 7: EDITING
A

FORM

4. From the Arrange tab choose Autoformat

5. Choose the Access 2007 format that we used in the prior exercises (if you hover

over the thumbnail it will give you the format name, it is the second one in the first row)

6.

Expand the form header section downward

7.

Switch back to the Design tab and select Label

104

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 7: EDITING
A

FORM

8. 9.

Drop the label in the header and type in Member CD List Change the font and size to the following:

10. Right

click on the label and choose Size to Fit

We should also lock out both the first name and last name fields from being edited. Members should only be added through the Member Form.
11. Select 12. Click

both fields at the same time by holding down your shift key. on Property sheet on the Design tab on the Data Tab of the Property sheet

13. Set Locked to Yes

If you set both Enabled to No and Locked to Yes, you will not be able to search on that field
14. Close and Save the design changes

UNIVERSITY TECHNOLOGY TRAINING CENTER

105

LESSON 7: EDITING
A

FORM

106

UNIVERSITY TECHNOLOGY TRAINING CENTER

8
Lesson
Less on 8

Queries
From this point use the CDClubForms database. After data has been entered using the forms, you can use queries to ask questions of your database. You can view and analyze fields from one table or join multiple tables together. A common reason for creating a Query is simply to join tables together to view related content. Queries are generally the basis of reports as well. Use the query to pull the fields and narrow down to the records desired, the report just formats the data for printing.

Creating a Query using the Query Wizard


CD List with Owners
The goal of this query is to create a master list of all CDs that are owned by the members and who owns them. We need to pull information from several tables to include all the fields needed for the query results.
1. On the Create tab choose Query Wizard

2. Leave at the default of Simple Query Wizard, click OK

UNIVERSITY TECHNOLOGY TRAINING CENTER

107

LESSON 8: QUERIES

3. In the Tables/Queries dropdown select tblCD

4. Add Title and YearReleased fields to the selected fields area 5. Switch to tblGenre

6. Add the Genre field to the selected fields 7. Switch to tblPerformer 8. Add the Performer field to the selected fields 9. Switch to tblMember

108

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

10. Add the FirstName and LastName fields to the selected fields

11. Click Next

OOPS!

In order for Access to know how these tables are related, and to pull fields from several tables in this query wizard, the tables have to be set up in the relationship design. In this version of the database, one relationship has been left out.
12. Click OK and it will show the relationships window 13. Close the show table dialog box 14. Recreate the missing relationship between tblGenre and tblCD

UNIVERSITY TECHNOLOGY TRAINING CENTER

109

LESSON 8: QUERIES

Dont forget to set Referential Integrity

15. Close the relationship window and start over at Step 1 of this Exercise 16. Leave the default of Detail and click Next

17. Save the Query as qryCDListWithOwners

110

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

Be descriptive in the query and report names, you may end up with several that are similar and you will want to be able to easily identify the purpose of the query or report just by looking at the name of it.

The query initially opens showing the results in query view

Modify a Query Using Design View


1. Switch to Design View using the view toggle

UNIVERSITY TECHNOLOGY TRAINING CENTER

111

LESSON 8: QUERIES

Did you Notice?

tblMemberCD is included in the query even though we did not select any fields from that table. We cannot make a connection directly from tblCD to tblMember. When we set up the relationships, we told Access that tblMemberCD is needed to join the two tables, so Access automatically added tblMemberCD into the query design.
2. Add a new field to the query to combine the Last and First Name fields into one

field called Owner. This field exists only within this query In the next blank column, type Owner :

The colon signifies that this is a new field name)

After the colon type LastName &, & FirstName .

The , *space+ between the fields leaves a comma and a space between the values so they do not run together)

Once you tab off the field, Access will add [ ] around each field name.

If you are working in a database that has spaces in the field names, you must put in the brackets manually, or Access will see each word as a field

3. Delete the original Name fields by hovering above the FirstName column until

you get a downward pointing arrow. Drag across to the Lastname column so both are highlighted. Then hit the Delete key

112

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

4. View the query results. Note that the new column name is the name we gave the

field.

5. Close and Save the Query design changes

Queries are dynamic, meaning as the data changes, the query results will change. If you query for a list of all the CDs in the club database today, and then again in a month, any CDs added, edited, or removed in the next month will change the query results. If Prince changes his name, for example, it will be reflected in the new results.
6. Open the Performer form 7. Find the record for Prince 8. Change the value from Prince to Artist Formerly Known as Prince 9. Double click on qryCDListWithOwners to run the query

Note the name change is reflected in multiple records even though you only changed it once

Before

After

UNIVERSITY TECHNOLOGY TRAINING CENTER

113

LESSON 8: QUERIES

Exercise 7: Creating a Query Using the Wizard


CD Master List
The CD List with Owners query shows multiple records for some CDs. This is because more than one Member owns that CD. We avoid having the CD information stored in the table multiple times by setting up the proper relational database structure, but we display it for every instance in the query results. To see just a unique list of all available CDs in the club dont include anything from the Member table.
1. In the Query objects, click on Create Query using Wizard 2. Pull fields from tblCD Title CDValue YearReleased

3. Switch to tblGenre and add the Genre field 4. Switch to tblPerformer and add the Performer field Click Next 5. Leave the default of Detail Click Next 6. Name it qryCDMasterList 7. Click Finish and the Query will open showing the results

114

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

Add a Sort to a Query


It might be hard to tell at this point that there is only one record per CD, so we can add a sort to the query.
1. Switch to Design View 2. In the Title column Sort row, choose Ascending from the drop down

3. Switch back to the query results view. Now the CDs will be in order by Title

End of Exercise

UNIVERSITY TECHNOLOGY TRAINING CENTER

115

LESSON 8: QUERIES

Adding Criteria to a Query


Criteria are used to restrict or narrow down which records are returned in the query. The results of using criteria on a query is similar to filtering on a form.
1. In the Queries objects window, right click on qryCDMasterList 2. Choose Copy 3. Right click again and choose Paste 4. Name the new query qryCDMasterWithCriteria 5. Open the new query in Design View 6. In the Criteria row under Genre, type Bluegrass

Access will add quotation marks around all text fields Criteria must be spelled exactly as it appears in the data

7. Switch to Query Results View

Only CDs with the Bluegrass genre will appear 8. Return to Design View

116

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

9. Add criteria for Year Released as >=2000 (greater than or equal to 2000) to

return CDs from 2000 and newer

Common Symbols Used for Criteria


> < >= <= = <>

Greater Than Less Than Greater Than or Equal To Less Than or Equal To Equal To (understood, does not have to be specified in criteria) Not Equal To

10. View the results

Adding more criteria narrows down the results even more.


11. Close and Save the query

UNIVERSITY TECHNOLOGY TRAINING CENTER

117

LESSON 8: QUERIES

Creating a Query in Design View


CDs on Loan Query
Create a query in Design View that displays only CDs out on Loan.
1. On the Create tab, under the Other section click on Design View

2. From the Show Table dialog box add the following tables: tblMember tblMemberCD tblCD tblPerformer

3. Close the Show Table Dialog box

4. Add the following fields by dragging them into the query design grid

From tblMember:
FirstName LastName

From tblCD:
Title

From tblPerformer:

118

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

Performer

From tblMemberCD:
LoanedToID DateOut

5. View the query results

The results include ALL CDs. Add criteria to check if there is a value in DateOut in order to return only those CDs out on loan 6. Return to Design View 7. In the DateOut Criteria row type is not null. Null is equivalent to blank or

empty.

8. View the

query results again

Only CDs currently on loan will be returned

UNIVERSITY TECHNOLOGY TRAINING CENTER

119

LESSON 8: QUERIES

Replacing the Loaned to Key with the Member Name


Lastly, we will want to replace LoanedToID with the actual Members name that has the cd out on loan.
1. Switch back to Design View 2. Using Show Table, Add tblMember to the Design View a second time so we can

link it to LoanedToID. It will be called tblMember_1 since tblMember is already

in the query.
3. Link MemberID in tblMember_1 to LoanedToID in tblMemberCD

4. Delete LoanedToID from the query design grid 5. Replace it with LastName from tblMember_1 6. Add Lent To: in front of the LastName field you just added to differentiate it

from the Lender

7. View the query results

120

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 8: QUERIES

8. Close and Save the query as qryCDOnLoan

Exercise 8: Creating a Query in Design View


Member Directory
Create a query that displays all the members and all their addresses in the database.
1.

On the Create tab, under the Other section click on Query Design

2. From the show table dialog box add tblMember, tblMemberAddress, and tblAddress Type 3. Add the Name fields from tblMember 4. Add AddressType from tblAddressType 5. From tblMemberAddress add the fields from Address1 thru Email

6. Sort Ascending by the Members Last Name

UNIVERSITY TECHNOLOGY TRAINING CENTER

121

LESSON 8: QUERIES

7. View the query results, you should have 22 records

Notice that you have more than one record for some Members. Even though they are only in the database once, they have more than one Address in the table. When you join the tables, it finds all the matches and displays them. 8.

Close and Save as qryMemberAddress

End of Exercise

122

UNIVERSITY TECHNOLOGY TRAINING CENTER

9
Lesson
Less on 9

Reports
Reports have the same dynamic properties that queries do. Reports are used to format data for printing. You can also use reports to create labels. Most reports are based on queries that pull information from multiple tables. More than one report can be generated from a single query (different sorting and layout options can be used and not every field from the query has to be pulled for the report).

Creating a Report Using the Auto Report option


Master list of all CDs in the club
1. From the Object Navigation pane choose qryCDMasterList 2. From the Create tab choose Report

UNIVERSITY TECHNOLOGY TRAINING CENTER

123

LESSON 9: REPORTS

3. Your report will be displayed

Touch Up Report
1. Switch to Design View 2. Edit the title to read CD Master List

3. The records should be sorted by Title. From the Grouping and Totals section of

the Design tab choose Group & Sort

124

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

4. Choose Add a Sort

5. Choose the Title field

6. View the report results again to see the changes

7. Close and Save the report as rptCDMasterList

UNIVERSITY TECHNOLOGY TRAINING CENTER

125

LESSON 9: REPORTS

Printing a report
1. Open rptCDMasterList by double clicking on it 2. Click on the Office button

3. Hover over Print and choose Print Preview to view the report first and make

and needed adjustments to the margins, paper orientation etc.

4. If you are ready to print click on Print, otherwise click on Close Print Preview

126

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

Exercise 9: Creating a Report Using Auto Report


List of CDs out on loan
1. From the Object Navigation pane choose qryCDOnLoan 2. From the Create tab choose Report

3. Your report will be displayed

Touch Up Report
1. Switch to Design View and 2. Edit the title to read CDs On Loan 3. Put spaces in the field labels as needed 4. Make the Name fields smaller to make room for the rest of the fields. 5. Close and Save the report as rptCDOnLoan

UNIVERSITY TECHNOLOGY TRAINING CENTER

127

LESSON 9: REPORTS

End of Exercise

Creating a Report Using the Wizard


List of CDs by Genre
A report that lists all the CDs in the club, grouped by Genre so Genre shows up once and all the CDs within that Genre are indented and shown below it.

1. From the Create tab, reports section, choose Report Wizard

128

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

2. In the Tables/Queries pick list choose the qryCDMasterList query

3. Add the following fields: Genre Title Performer

4. Click Next 5. View data by tblGenre (what we want to group by) Click Next

UNIVERSITY TECHNOLOGY TRAINING CENTER

129

LESSON 9: REPORTS

6. No additional grouping levels needed so Click Next

7. Choose Title to sort by (within each Genre grouping) Click Next

8. Leave layout as the default, Stepped and Portrait Click Next

130

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

9. Choose the report style Access 2007 (to keep consistent style with the rest of

the database) Click Next

10. Name the report rptCDMasterby Genre Click Finish

11. The report displays in Print Preview mode, Click on Close Print Preview to

go to design view

12. Edit the title to read CD Master by Genre 13. Select

the Genre field and make it wider

UNIVERSITY TECHNOLOGY TRAINING CENTER

131

LESSON 9: REPORTS

14. Select

the Performer field and make it wider (dont go beyond the right border of the report)

15. View

the report

16. Close and Save

the design changes

132

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

Exercise 10: Creating a Report Using the Wizard


List of CDs by Performer
A report that lists all of the CDs in the club, grouped by Performer so the Performer shows up once and all the CDs by that person or group are indented and shown below it. We will use the same query from the last exercise, just grouping it differently. We can use our database more efficiently by reusing queries.

1. From the Create tab, reports section, choose Report Wizard

UNIVERSITY TECHNOLOGY TRAINING CENTER

133

LESSON 9: REPORTS

2. In the Tables/Queries pick list choose the qryCDMasterList query

3. Add the following fields: Performer Title Genre

4. Click Next 5. View data by tblPerformer (what we want to group by) Click Next

134

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

6. No additional grouping levels needed so Click Next

7. Choose Title to sort by (within each Performer grouping) Click Next

UNIVERSITY TECHNOLOGY TRAINING CENTER

135

LESSON 9: REPORTS

8. Leave layout as the default, Stepped and Portrait Click Next

9. Choose the report style Access 2007 (to keep consistent style with the rest of

the database) Click Next

10. Name the report rptCDMasterbyPerformer Click Finish 11. The report displays in Print Preview mode, Click on Close Print Preview to go

to design view

12. Edit the title to read CD Master by Performer

136

UNIVERSITY TECHNOLOGY TRAINING CENTER

LESSON 9: REPORTS

13. Select

the Performer field and make it wider (dont let the fields go beyond the right border of the report)

14. View

the report

15. Close

and Save the design changes

End of Exercise

UNIVERSITY TECHNOLOGY TRAINING CENTER

137

10
Lesson
Less on 10

Final Touches
Menu
To further enforce not entering data into the tables and to make the database as easy to navigate as possible, you can use the Switchboard wizard to create a menu system.

Creating a Switchboard
1. On the Database tools tab, under Database tools, choose Switchboard Manager 2. The first time you run it you will be prompted to create a new switchboard

3. Click Yes to create a new Switchboard

UNIVERSITY TECHNOLOGY TRAINING CENTER

139

LESSON 10: FINAL TOUCHES

4. Click Edit

5. Click New

6. Add the Text for the first Item: Enter Members 7. Choose Open Form in Add Mode in the Command line (this will only allow

some to Add a new member, they cannot view existing)


8. Choose the form name in the Form line

9. Click OK 10. Click New to add the next menu item, this one will allow the user to view existing

members

140

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX A: FINAL TOUCHES

11. Click OK 12. Repeat for the rest of the forms

UNIVERSITY TECHNOLOGY TRAINING CENTER

141

LESSON 10: FINAL TOUCHES

13. Create the items for the three reports. Menu items for Reports are created the

same way, except you choose Open Report for the Command

If you try to add another item at this point you will get a message. Access does limit each switchboard to 8 items, but you can have multiple switchboards, one for forms, one for reports, etc.

14. Click OK, thats all we are going to add to the switchboard for now 15. Click Close on the 2 Switchboard screens

142

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX A: FINAL TOUCHES

Display Switchboard when Database Opens


1. From the Office button choose Access options

2. Choose Current database

3.

Under Display Form choose Switchboard from the dropdown list

4. Click OK to save and close

UNIVERSITY TECHNOLOGY TRAINING CENTER

143

LESSON 10: FINAL TOUCHES

5. You will be prompted to close and reopen the database to see the results of the

change. Click OK.

6. Close the database and Reopen to see the Switchboard

144

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX A: FINAL TOUCHES

Database Maintenance and Backups


As you work with your Access database, the file size will grow. If the file size looks out of line with the amount of data you have stored or it starts running really slowly, its might be time to compact your database. As you add, delete, import, and move data in the database, Access takes more space as it needs it. The space is not automatically relinquished; it is up to you to decide when to give it back. Think of it as defragging your hard drive. If your database ever gets corrupted by a power outage or hard drive failure, the repair part of the Compact and Repair should solve any issues you might have.

Compact and Repair Database


The frequency with which you run Compact and Repair varies on how heavily your database is used. It should be run a minimum of once a month and more often if needed. No one else should be accessing the database while Compact and Repair running. It runs fairly quickly, but the length of time will depend on the amount of data and your computer speed.
1. Under the Office menu choose Manage 2. Then choose Compact and Repair

The database will be closed and reopened when it has completed the process.

UNIVERSITY TECHNOLOGY TRAINING CENTER

145

LESSON 10: FINAL TOUCHES

Backing Up the Database


Backups are critical to any file but especially Access databases. There are so many things in Access that cannot be undone that backups are recommended daily, as well as before any major changes are done to the database. In Access 2003 and newer, you now have a menu option for running a backup. It will ask you where you would like to store the backup and adds a date stamp to the file name. If your Access database is stored on a server, speak with your server administrator about including the file in the nightly backups.
1. 2.

Under the Office button choose Manage Then choose Back Up Database

3.

You will be prompted for a location and name, click Save when you are ready to run the backup.

146

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX A: FINAL TOUCHES

UNIVERSITY TECHNOLOGY TRAINING CENTER

147

A
Appendi x A

Appendix

Using the Label Report Wizard


Create formatted address labels for all the members in the club.
1. Select the query qryMemberAddress in the Object Navigation Pane 2. On the Create tab, Reports section choose Labels 3. Choose Avery 5160 as the label size

4. Click Next

UNIVERSITY TECHNOLOGY TRAINING CENTER

149

APPENDIX A: USING
THE

LABEL REPORT WIZARD

5. Choose a Font and Font Size (this can always be adjusted later)

6. Click Next 7. Add fields to the Prototype Label area by selecting them from the Available Fields section.

Note:

More than one field can be placed on a line. To add to another line, click in that line, hitting Enter will take you to the next step in the wizard. Add spaces where appropriate and a comma between City and State.

150

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX A: USING
THE

LABEL REPORT WIZARD

8. Choose to sort by Last Name

9. Name the report rptMemberAddressLabels and click Finish. The report

will open in print preview mode.

UNIVERSITY TECHNOLOGY TRAINING CENTER

151

B
Appendi x B

Appendix

Creating a Query Using Aggregate Functions


Next we will create a query using aggregate functions to calculate Count, Sum, Average, Min, and Max of the values of CDs within each genre.
1. Create a new query in Design View 2. Add tblCD and tblGenre to the query design 3. Add Genre from the tblGenre to the query grid 4. Add CDValue from tblCD to the query grid 5. From the Show/Hide section of the Design tab, choose Totals.

This will display a new line on the query grid labeled Total. The default value for each field is Group By. Group By is used to combine all like values of that field

UNIVERSITY TECHNOLOGY TRAINING CENTER

153

APPENDIX B: CREATING
A

QUERY USING AGGREGATE FUNCTIONS

6. We want to group by Genre so leave the Group By value in the Genre field

If we leave Group By in the Value field as well and Preview the query, we would see the query shows each unique Value within each Genre, thats not what we are looking for

7. Change the Group By under the CDValue field to Sum using the drop down list

8. Right click on the CDValue column in the Query grid and choose Properties

154

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX B: CREATING
A

QUERY USING AGGREGATE FUNCTIONS

9. Choose Currency from the Format dropdown

10. Preview the Query

The new temporary name for the CDValue column is SumOfCDValue. We are now seeing a sum of the values of all CDs within each Genre
11. Return to Design View and add the Title field from tblCD 12. Change Group By to Count in the Total row under Title

UNIVERSITY TECHNOLOGY TRAINING CENTER

155

APPENDIX B: CREATING
A

QUERY USING AGGREGATE FUNCTIONS

13. Preview the query

We now have a count of how many CD Titles exist under each Genre
14. Return to Design View and add the CDValue field three more times 15. Change one of each of the newly added CDValue fields to Avg, Min, and Max

16. Format each of the three new CDValue columns to Currency

Hint: you can leave the properties window open and click on another field to set its properties.
17. Preview the query results

1 8.

Close and Save the query as qryCDTotalsbyGenre

156

UNIVERSITY TECHNOLOGY TRAINING CENTER

C
Appendi x C

Appendix

Exporting Query Results


1. Open qryCDTotalsbyGenre in query results view (query created in prior

appendix)
2. When the query results are on the screen, from the External Data tab, choose Excel

3. You will be prompted for the file location and format 4. Choose to Export with formatting and to Open the destination file

5. Click ok and an Excel document will open showing the query data

UNIVERSITY TECHNOLOGY TRAINING CENTER

157

APPENDIX C: EXPORTING QUERY RESULTS

6. You can then add totals or other Excel functions

You can also choose to save as Text, html, xml and other options.
7. When you return to Access you will see a screen asking if you want to save your

export steps

158

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX C: EXPORTING QUERY RESULTS

If this is something you will do on a regular basis and you want to automate it, click on the box. You will be given more options:

8. We will not be saving this export so we can just click Close

UNIVERSITY TECHNOLOGY TRAINING CENTER

159

D
Appendi x D

Appendix

Creating a Member Address Report Using the Wizard


You will be creating a report listing all of the Members along with their address(es). You want to group by the Member and show their address indented underneath.

1. From the Create tab, reports section, choose Report Wizard

2. In the Tables/Queries pick list, choose the qryMemberAddress query

UNIVERSITY TECHNOLOGY TRAINING CENTER

161

APPENDIX D: CREATING
A

MEMBER ADDRESS REPORT USING

THE

WIZARD

3. Add the following fields, in order LastName FirstName AddressType Address1 Address2 City State Zip

4. Click Next 5. View data by tblMember , click Next 6. No additional grouping, click Next 7. Sort by AddressType, click Next 8. Set layout as Stepped and Landscape, click Next

9. Choose the report style Access 2007, click Next 10. Name the report rptMemberAddress , click Finish

162

UNIVERSITY TECHNOLOGY TRAINING CENTER

APPENDIX D: CREATING
A

MEMBER ADDRESS REPORT USING

THE

WIZARD

11. Close

Print Preview

12. Edit the report title and add spaces in the field labels, switch between design and

report view as needed Change the Title at the top of the report to Member Address List Edit the Names, Address Type, and Address labels (not field names) to add spaces between the words Shrink or expand fields as needed so data is not getting cut off (as much as possible)(dont let the fields go beyond the right border)

13. Close the report and Save the changes made

UNIVERSITY TECHNOLOGY TRAINING CENTER

163

Appendix

E
Appendi x E

Exporting a Report
Reports in Access can easily be exported to Word for use as an email attachment.
1. In the Reports objects navigation pane, double click on rptCDMasterbyPerformer 2. Go to Print Preview using the Office button 3. In the Data section click on Word

You will be prompted for the file name and location to save the document. The report results will be exported to Word as an *.rtf (rich text format) file.

UNIVERSITY TECHNOLOGY TRAINING CENTER

165

APPENDIX E: EXPORTING
A

REPORT

4. Click the option to open the destination file and Word will launch and display the

document. Notice that some formatting will not show up (e.g., lines and other graphical elements.) because the rtf format can only display text.

166

UNIVERSITY TECHNOLOGY TRAINING CENTER

You might also like