Sei sulla pagina 1di 174
Access2007&2010: BasicDatabaseDevelopment

Access2007&2010:

BasicDatabaseDevelopment

O I T

T E C H N O L O G Y

T R A I N I N G

S E R V I C E S

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 percent postconsumer material. ©2011 Regents of the University of Minnesota. All rights reserved. 1 0

Table of Contents

LESSON 1

INTRODUCTION TO DATABASES

Database Design Vocabulary

Relationships

Design Process

LESSON 2

BUILDING A DATABASE IN ACCESS

Create an Access Database

Set Access Options

Creating Tables

Exercise 1: Creating Tables

Creating a Join Table

1

LESSON 4

31

CREATING RELATIONSHIPS

31

1

Print the design

35

1

Removing Tables from the Diagram

36

2

Deleting or Editing Relationships

36

3

 

LESSON 5

37

7

MODIFYING TABLES AND RELATIONSHIPS

37

7

Adding the New Foreign Key Field

38

7

8

10

LESSON 6

41

17

CREATING INTERFACES TO

18

INTERACT WITH DATA

41

 

Using Forms vs. Tables for data entry

41

LESSON 3

19

Creating the Member Status type

 

Entry Form

42

SETTING FIELD PROPERTIES

19

Resizing text fields

20

Exercise 3: Creating Entry Forms Using Multiple Items Form Option

49

Input Masks

21

Handling One-to-Many

Default values

24

Relationships with Subforms

55

Format number fields

26

Exercise 5: Creating a Subform using Autoform

64

Exercise 2: Setting field properties

28

Linking the Main form and Sub Form

71

 

Navigating Records and Entering Test Data

73

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

i

Creating Forms using the wizard

74

Exercise 6: Creating the CD entry form using the Wizard

79

LESSON 6 CONTINUED

Adding to combo box lists “on the fly”

84

Finding a Record on a Form

86

Using a Combo Box to Find Records on the Form

89

Creating the Member CD Form and Subform in Design View

93

Date picker

101

LESSON 9

123

REPORTS

123

Creating a Report Using the Auto Report option

123

Exercise 9: Creating a Report Using Auto Report

127

Creating a Report Using the Wizard

128

Exercise 10: Creating a Report Using the Wizard

133

LESSON 10

139

FINAL TOUCHES

139

 

Menu

139

LESSON 7

103

Database Maintenance and Backups

145

EDITING A FORM

103

 

Modifying a Form

 

103

LESSON 8

107

 

QUERIES

107

Creating a Query using the Query Wizard

107

Exercise 7: Creating a Query Using the Wizard

114

Adding Criteria to a Query

 

116

Creating a Query in Design View

118

Exercise 8: Creating a Query in Design View

121

End of Exercise

 

122

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

ii

APPENDIX A

149

USING THE LABEL REPORT WIZARD

149

APPENDIX B

153

CREATING A QUERY USING AGGREGATE FUNCTIONS

153

APPENDIX C

157

EXPORTING QUERY RESULTS157

APPENDIX D

161

CREATING A MEMBER ADDRESS REPORT USING THE WIZARD

161

APPENDIX E

165

EXPORTING A REPORT

165

I N T R O D U C T I O N

T O

L E S S O N

1 :

D A T A B A S E S

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

iii

Lesson

1

Introduction to Databases

Records

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:

Fields

and Release Year Table : A group of records Example: Fields Table TITLE GENRE PERFORMER YEAR
and Release Year Table : A group of records Example: Fields Table TITLE GENRE PERFORMER YEAR

Table

TITLE

GENRE

PERFORMER

YEAR

OWNER

The Best of Van Morrison

Rock

Van Morrison

1990

Amy Jones

Positive Friction

Americana

Donna the Buffalo

2000

Amy Jones

Natural

Brazilian

Celso Fonseca

2003

Amy Jones

 

Jazz

Miles Davis

1991

Amy Jones

 

Jazz

Miles Davis

1991

Amy Jones

Rice, Rice, Hillman and Pedersen

Bluegrass

Rice, Rice, Hillman and Pedersen

1999

Amy Jones

Man of Constant Sorrow

Bluegrass

Ralph Stanley

2001

Amy Jones

Sketches of Spain

Jazz

Miles Davis

1991

Andy Jackson

Man of Constant Sorrow

Bluegrass

Ralph Stanley

2001

Andy Jackson

I Wonder Where You Are Tonight

Bluegrass

Del McCoury

2002

Andy Jackson

A

Day Without Rain

New Age

Enya

2004

John Smith

In

Pieces

Country

Garth Brooks

2002

John Smith

American Idiot

Pop

Green Day

2004

John Smith

Sketches of Spain American Idiot Pop Green Day 2004 John Smith Kind of Blue Example of a table in

Kind of BluePop Green Day 2004 John Smith Sketches of Spain Example of a table in a flat/Excel

Example of a table in a flat/Excel file

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

1

L E S S O N

1 :

I N T R O D U C T I O N

T O

D A T A B A S E S

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

times, as are some of the Genres and Owners. Relationships Relationship diagram showing the relationships between

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

2

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

I N T R O D U C T I O N

T O

L E S S O N

1 :

D A T A B A S E S

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.

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

3

L E S S O N

1 :

I N T R O D U C T I O N

T O

D A T A B A S E S

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

I N T R O D U C T I O N

T O

L E S S O N

1 :

D A T A B A S E S

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

Define Relationships

losing history (such as Member Status). Define Relationships Refine and Test Now is the time to

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:

Used for viewing, adding, and updating data

Queries:

Used to ask Access to return a selected portion of your data

Reports:

Used to format the data for printing

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

5

Lesson

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).

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

7

L

E S S O N

2 :

B U I L D I N G

A

D A T A B A S E

I N

A C C E S S

Student\Desktop\Access 2010 Bas…
Student\Desktop\Access 2010 Bas…
B A S E I N A C C E S S Student\Desktop\Access 2010 Bas… 2

2

1

4

E I N A C C E S S Student\Desktop\Access 2010 Bas… 2 1 4 3

3

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:

know whether the content is safe or not. In Access 2007: 1. You will see a

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

8

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

In Access 2010:

B U I L D I N G

A

D A T A B A S E

L E S S O N

2 :

I N

A C C E S S

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.

few settings to consider changing. 1. Open Access Options.  Click File (In 2007, Select the

Click File (In 2007, Select the Office

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

button in the upper left corner).

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.

hand pane.  Change Default text field size: to 35 . U N I V E

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

9

L

E S S O N

2 :

B U I L D I N G

A

D A T A B A S E

I N

A C C E S S

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

pane.  Uncheck Enable Layout View for this Database 4. After the changes have been made

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

B U I L D I N G

A

D A T A B A S E

L E S S O N

2 :

I N

A C C E S S

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.

the View toggle button on the far left side of the ribbon. 2. Access will ask

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

to save the table first. Type in the table name tblMember . 3. Click OK Table

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

11

L

E S S O N

2 :

B U I L D I N G

A

D A T A B A S E

I N

A C C E S S

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

of Field Name, Data Type, and Description.

for entry of Field Name , Data Type , and Description . Navigation Pane Design View
for entry of Field Name , Data Type , and Description . Navigation Pane Design View

Navigation

Pane

Design View of tblMember

Field Name Best Practices

Pane Design View of tblMember Field Name Best Practices Table Design View  Keep it short

Table

Design View

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.

12

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

Data Type options

B U I L D I N G

A

D A T A B A S E

L E S S O N

2 :

I N

A C C E S S

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.

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

13

L

E S S O N

2 :

B U I L D I N G

A

D A T A B A S E

I N

A C C E S S

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.

find and display the closest matching data type for you. 2. Once you have entered all

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.

be asked to confirm design changes on a table, form etc. 3. Click Yes 4. To

3. Click Yes

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

create another table click on the Create tab on the Ribbon 14 U N I V

14

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

5. Then Click Table

5. Then Click Table 6. Switch to Design View B U I L D I N

6. Switch to Design View

B U I L D I N G

A

D A T A B A S E

L E S S O N

2 :

I N

A C C E S S

D I N G A D A T A B A S E L E S

7. Save this table as tblMemberAddress

: I N A C C E S S 7. Save this table as tblMemberAddress U

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

15

L

E S S O N

2 :

B U I L D I N G

A

D A T A B A S E

I N

A C C E S S

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

you need to enter foreign Zip codes.) 8. Repeat for tblCD Note: If you use Value

Note:

If you use Value instead of CD V alue you would get the following message:

If you use Value instead of CD V alue you would get the following message: Click

Click OK and correct the field name.

16

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

B U I L D I N G

A

D A T A B A S E

L E S S O N

2 :

I N

A C C E S S

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:

2. Switch to design view and create the following table: 3. Save and close tblGenre 4.

3. Save and close tblGenre

4. Repeat for the following 2 tables:

and close tblGenre 4. Repeat for the following 2 tables: End of Exercise U N I
and close tblGenre 4. Repeat for the following 2 tables: End of Exercise U N I

End of Exercise

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

17

L

E S S O N

2 :

B U I L D I N G

A

D A T A B A S E

I N

A C C E S S

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 can’t 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.”

or first initial of each table name followed by “ID.” Note When working with an existing

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

Setting Field Properties

Lesson

3

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.

for foreign key fields to the corresponding primary key. General tab for a Text field U

General tab for a Text field

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

19

L

E S S O N

3 :

S E T T I N G

F I E L D

P R O P E R T I E S

S S O N 3 : S E T T I N G F I E

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

Size value in the General tab 4. Change the value to 2 20 U N I

20

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

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

S E T T I N G

F I E L D

L E S S O N

3 :

P R O P E R T I E S

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.

2. Click in the Input Mask field in the General tab. U N I V E

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

21

L

E S S O N

3 :

S E T T I N G

F I E L D

P R O P E R T I E S

The

O N 3 : S E T T I N G F I E L D

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

The (ellipses) button will appear to the right of the field 3. Click on the ellipses

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

You will be asked to save changes made to the table design 5. Click Yes 6.

5. Click Yes

6. The input mask wizard will appear. Choose the Phone Number option (first one in the list)

Choose the Phone Number option (first one in the list) 22 U N I V E

22

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

S E T T I N G

F I E L D

L E S S O N

3 :

P R O P E R T I E S

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

It section, type in a phone number and see how it works. Note: With all Input

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 Mask’s 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.

phone number input mask will look like in the general tab. U N I V E

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

23

L

E S S O N

3 :

S E T T I N G

F I E L D

P R O P E R T I E S

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 today’s date automatically.

1. Select the State field in tblMemberAddress

1. Select the State field in tblMemberAddress 2. In the Default Value field on the general

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

24

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

S E T T I N G

F I E L D

L E S S O N

3 :

P R O P E R T I E S

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

off the field it will put double quotes around the value. 4. Choose the Country field

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()

field 7. In the Default Value field, type Date() Note: Be sure to include both parentheses!

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.

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

25

L

E S S O N

3 :

S E T T I N G

F I E L D

P R O P E R T I E S

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 formatdepending 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)

Long Integer: -2,147,483,648 to 2,147,483,647 (rounds up or down, default for Primary Key auto number fields)

Single:

-3.4x10 38 to 3.4x10 38 (up to 7 decimal places, will not round)

Double:

-1.797x10 308 to 1.797x10 308 (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

table name in the Object Navigation Pane on the left side 2. Type 14.99 in the

2. Type 14.99 in the CDValue field.

on the left side 2. Type 14.99 in the CDValue field. 26 U N I V

26

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

S E T T I N G

F I E L D

L E S S O N

3 :

P R O P E R T I E S

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

field to select it 6. Change the DataType to Currency 7. Switch back to Datasheet View

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

27

L

E S S O N

3 :

S E T T I N G

F I E L D

P R O P E R T I E S

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

End of Exercise

S E T T I N G

F I E L D

L E S S O N

3 :

P R O P E R T I E S

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

29

Creating Relationships

Lesson

4

In Access, you create the relationships between tables—which you’ve 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

on the Database Tools Tab 2. Click on Relationships U N I V E R S

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

31

L

E S S O N

4 :

C R E A T I N G

R E L A T I O N S H I P S

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.

click on the first table in the list, then the last table. 4. Click Add then

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

in a blank section of the relationships window and choose Show Table or use the Show

or use the Show Table button on the Design tab

in a blank section of the relationships window and choose Show Table or use the Show

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

L E S S O N

4 :

R E L A T I O N S H I P S

C R E A T I N G L E S S O N 4 :

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.

the mouse you will see the Edit Relationships dialog box. Verify you have selected the correct

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.

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

33

L

E S S O N

4 :

C R E A T I N G

R E L A T I O N S H I P S

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 wouldn’t want someone to delete a CD from the database that multiple people own and may be out on loan.

database that multiple people own and may be out on loan. Note: In Access 2003, setting

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

L E S S O N

4 :

R E L A T I O N S H I P S

C R E A T I N G L E S S O N 4 :

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.

to the relationships window using the Database Tools tab. 2. Select the Relationship Report 3. Switch

2. Select the Relationship Report

Database Tools tab. 2. Select the Relationship Report 3. Switch to Landscape layout U N I

3. Switch to Landscape layout

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

35

L

E S S O N

4 :

C R E A T I N G

R E L A T I O N S H I P S

E S S O N 4 : C R E A T I N G R

4. After you have printed the report close the report preview window using the X in the upper right hand corner.

preview window using the X in the upper right hand corner. 5. Choose No when it

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

Lesson

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. It’s 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

from your desktop 2. Click on the Create tab 3. Then click Table U N I

3. Then click Table

desktop 2. Click on the Create tab 3. Then click Table U N I V E

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

37

L

E S S O N

5 :

M O D I F Y I N G

T A B L E S

A N D

R E L A T I O N S H I P S

4. Switch to design view

5. Create the fields as shown below:

Switch to design view 5. Create the fields as shown below: 6. Edit field properties 

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

by right clicking on the table name in the navigation pane  Right click on the

Right click on the DateCreated row and choose Insert Rows

Right click on the DateCreated row and choose Insert Rows 38 U N I V E

38

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

M O D I F Y I N G

T A B L E S

A N D

L E S S O N

5 :

R E L A T I O N S H I P S

Add MemberStatusID as a Number type in the new row

 Add MemberStatusID as a Number type in the new row 2. Edit the Relationships 

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

 Close and Save the relationship design changes Updated Relationships U N I V E R

Updated Relationships

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

39

Lesson

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. Don’t 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.

is more suited to managing the tables and keys itself. Example of a table with multiple

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

41

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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

3. In the Forms section, select the Multiple Items icon Types of Forms Single/Columnar Form: Displays

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.

create an easy form to maintain the values in those tables. This method of form creation

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

42

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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

Active

Inactive

Enter the following values:  Active  Inactive Note how the icon to the left changes

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.

selecting the Home tab, then using the view toggle button. Design view of a form When
selecting the Home tab, then using the view toggle button. Design view of a form When

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.

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

43

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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

“ tbl ” and put a space between Member and Status 8. Remove the MemberStatusID field.

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.

form.  Select the field and hit Delete on your keyboard. Access automatically repositions the other

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.

words in the labels that are in the header section. 44 U N I V E

44

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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.

field will show a green triangle in the upper left corner. Click on the triangle to

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

Click on it to see the Access tips for fixing the problem. The highlighted fields are

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

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

45

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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

 Data tab change Enabled to No and Locked to Yes Note about Enabled and Locked

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 user’s part because it acts like one should be able to type in the field

Enabled=No AND Locked = Yes

and not allow a cursor into the field.

will lock the field but not grey it out

46

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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 “Active”status 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.

down earlier as being assigned to the “Active” status. 4. Close and save tblMember U N

4. Close and save tblMember

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

47

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

48

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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.

form is used to add and edit the values in tblPerformer. 1. In the Object Navigation

1. In the Object Navigation pane, click on tblPerformer

2. From the ribbon menu choose Create

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

49

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

3. From the Forms section choose Multiple Items

H D A T A 3. From the Forms section choose Multiple Items 4. Switch to

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)

the field properties (set Enabled to No and Locked to Yes) 9. Save and name the

9. Save and name the form as frmPerformer

10. Switch to Form View and enter test data:

Enya

Garth Brooks

Green Day

50

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

Ludwig van Beethoven

Ralph Stanley

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

51

L

E S S O N

6 :

C R E A T I N G

Part 2:

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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.

form is used to add and edit the values in tblAddressType. 1. In the Object Navigation

1. In the Object Navigation pane, click on tblAddressType

2. From the ribbon menu choose Create

3. From the Forms section choose Multiple Items

Create 3. From the Forms section choose Multiple Items 4. Switch to Design View using the

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 “tbland put a space between address and type

6. Delete the AddressTypeID field

7. Put appropriate spaces in the AddressType and DateCreated labels

52

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

8. Lock down the DateCreated field using the field properties (set Enabled to No and Locked to Yes)

the field properties (set Enabled to No and Locked to Yes) 9. Save and name the

9. Save and name the form frmAddressType

10. Switch to Form View and enter test data:

Home

Work

School

End of Exercise

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

53

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

54

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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.

is the main form that shows one member record at a time. 1. In the object

1. In the object navigation pane select tblMember

2. Choose the Create tab

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

55

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

3. Under the Forms section choose Form

T W I T H D A T A 3. Under the Forms section choose Form
T W I T H D A T A 3. Under the Forms section choose Form

Newly created member form

4. Go to the Home tab and Switch to Design View

form 4. Go to the Home tab and Switch to Design View frmMember in Design View

frmMember in Design View

56

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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 won’t delete the key field in this case since the MemberID could be referenced and searched by within the database (like an account number)

Put spaces between First, Middle, and Last and Name

Put a space between Date and Created

8. 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).

(it will place an orange border around the selected object).  Move your mouse to the

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).

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

57

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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

box wizard will appear, leave the default option, click Next  Select tblMemberStatus and click Next

Select tblMemberStatus and click Next

click Next  Select tblMemberStatus and click Next  Move MemberStatusID and MemberStatus fields into

Move MemberStatusID and MemberStatus fields into the

selected fields area by double clicking or using the > button, click next.

by double clicking or using the > button, click next. 58 U N I V E

58

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

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

Select MemberStatus as the field to sort by, click next  The next screen is a

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.

field we selected) is automatically hidden from the user. U N I V E R S

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

59

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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.

the matching foreign key field MemberStatusID, click next.  Type in the text you want for

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

label part of the combo box: Member Status, click Finish 60 U N I V E

60

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

C E S T O I N T E R A C T L E S

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.

10. We need to shorten the fields to make room to add a subform. Group all of the fields in the detail section

Click anywhere above the MemberID Field (not the label, we don’t 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.

right until all fields are within the box it has created. U N I V E

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

61

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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

all the fields will be grouped and showing the orange border Make sure that the labels

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.

the group to the left to shorten all the fields at once. 13. Release your mouse

13. Release your mouse around the 4 inch mark

at once. 13. Release your mouse around the 4 inch mark 14. Lock down the DateCreated

14. Lock down the DateCreated field by setting enabled to no and locked to yes in the field’s properties

62

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

15. Close and Save the form as frmMember

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

63

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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.

for a member once it is connected to the member form. 1. In the object navigation

1. In the object navigation pane select tblMemberAddress

2. Choose the Create tab

3. Under the Forms section choose Form

the Create tab 3. Under the Forms section choose Form 64 U N I V E

64

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

L E S S O N

6 :

W I T H

D A T A

C E S T O I N T E R A C T L E S

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

tblAddressType  Select AddressTypeID and AddressType  Sort by AddressType  Store the value in

Sort by AddressType

Store the value in AddressTypeID

U N I V E R S I T Y

T E C H N O L O G Y

T R A I N I N G

C E N T E R

65

L

E S S O N

6 :

C R E A T I N G

I N T E R F A C E S

T O

I N T E R A C T

W I T H

D A T A

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,