• No results found

IN THIS PROJECT, YOU LEARN HOW TO

N/A
N/A
Protected

Academic year: 2021

Share "IN THIS PROJECT, YOU LEARN HOW TO"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

Project 11 Creating A Customized Database UNIT 2: 875

UNIT 2

PROJECT 11

C REATING

A C USTOMIZED D ATABASE

IN THIS PROJ ECT, YOU LEARN H OW TO

Examine a Database and Its Objects

Create Tables and Set Field Properties in Design View

Create Relationships

Add and Delete Records

Create a Form Using the Form Wizard

Create a Report Using the Report Wizard

(2)

UNIT 2: 876 Using Productivity Software

WHY WOULD I D O THI S?

A database is a collection of related facts—or data—stored together in one file.

Mi cr o soft Offi c e Acc es s is a computerized database management system that enables you to store, retrieve, analyze, and print information. It is a system for managing large amounts of data. Companies use databases for many purposes: to manage customer files, to track orders and inventories, and for marketing purposes. An individual might set up a database to track household expenses or manage a list of family, friends, and business addresses. Teachers often set up a database to track students’ grades and other class information. A database enables the user to access and manage thousands of pieces of data in an organized, efficient, and accurate manner.

To begin using Access, there are a number of terms that you need to understand. An Access database consists of tables, querie s, forms, reports, pages, macros, and modules, which are all generally known as objects. These objects work together to store, search, input, report, and automate the data. The following is a brief explanation of the purpose of each object.

Tables are the foundation of the database because they store the data that makes up the database. Each table stores a set of related data.

Queries are used to sort, search, and limit the data to just those records that you want to see.

Forms are used to input, edit, or view data, generally one record at a time.

Reports are used to summarize information for printing and presentation of the data.

Pages are a type of Web page designed for viewing and working with data from the Internet or over an intranet.

Macros are used to automate existing Access commands.

Modules are programs in the Visual Basic programming language that are used to customize the database for special needs.

In this project, you first examine the four main objects in a database: tables, forms, reports, and queries. Then you open another database, add a table, add records, and create a form and a report. Queries are covered in depth in Project 12.

VISU AL SUMM ARY

In this project, you add objects to a database for the Armstrong Pool, Spa, and Sauna Company. You create an Orders table and enter new records. You create a Contractors form and a Contact List report. Figure 11.1 shows the form that you create, and Figure 11.2 shows the report.

(3)

Project 11 Creating A Customized Database UNIT 2: 877

LESSO N 1: Ex a mi ni ng a Dat ab ase an d Its Obj ects

This textbook introduces you to the four main Microsoft Office Access objects: tables, forms, reports, and queries. Each object has at least two views. The Design view is used to create and modify objects, whereas the object view is used to view the data. In tables or queries this is known as the Datasheet view, in a form it is the Form view, and in a report it is the Print Preview of the report.

In this lesson, you open a database and save a backup copy of the database. You then open each of the four main objects to see the data and to examine the design of a table and a query.

All of these exercises can be completed with Microsoft Office 2007. Instructions throughout the lessons are based on the Windows XP operating system, running Microsoft Office 2007. Your screen may differ slightly from the figures shown, even if you are running Office 2007.

Form created

FIGURE 1 1 .1

Report created

FIGURE 1 1 .2

(4)

UNIT 2: 878 Using Productivity Software

To Examine the Database window

1. Start Microsoft Access; click More on the Open Recent Database task pane. The Open dialog box displays. As with other applications, use the Open dialog box to locate and open files.

2. Locate and open AC_1101 in the Student folder for this chapter. Click the Office button, point to Save As, and then from the submenu, click Access 2002-2003 Database. If a Read-Only bar displays under the Ribbon, click Save As on the right end of the bar. The Save As dialog box displays. Here you can save the file with a new name and in a folder of your choice.

3. Navigate to the drive and folder where you are saving your files; in the File name box type Personnel and then click Save.

4. In the Security Warning bar under the Ribbon click the Options button, click Enable this Content, and then click OK. The file opens and displays the Access window. The Tables object displays in the Navigation Pane on the left, and one table—Personnel—is listed. The Access window displays four Access tabs on the Ribbon—Home, Create, External Data, and Database Tools. Notice that the title bar displays the filename and (Access 2002-2003 file format). The file format refers to the version of Access that you selected when you saved the file. This file can be opened with earlier versions of Access.

If you hav e pro blems...

The latest version of Windows has more sensitive security precautions than earlier versions. Depending on your version of Windows and the security settings on your computer, you may see a Security Warning box every time you open an Access database. This warning box advises you that the file may not be safe to open if it contains code that was intended to harm your files. Because databases use objects that are interconnected and may contain macros, this security warning displays as a precaution. Macros in Access are used to manage files. The files that you use in this textbook are safe to open, so each time you see this security warning, click Open to continue.

5. Examine Figure 11.3 to identify each component of the Access window and read the explanation for each part of the window found in Table 11.1 that follows this figure.

Object list arrow

Tables object list Navigation Pane

Shutter Bar Open/Close Button

FIGURE 1 1 .3

(5)

Project 11 Creating A Customized Database UNIT 2: 879 COMP ONE NT DE S CRIP TION

Access Ribbon Four tabs—Home, Create, External Data, and Database Tools—

display on the Access Ribbon. Contextual tabs will become

available when objects are open and will change depending on the view of the object displayed.

Navigation Pane Used to navigate between objects. The currently active object displays in orange. The names of available objects for that type of object are listed under the object type. In Figure 11.3, Tables is the object type and Personnel is the only table that is listed for this database. Personnel is also the active object as seen by the orange highlighting. You can display one or all types of objects.

Object list The objects for the currently active object type(s).

Object list arrow Displays a list of options for organizing and displaying objects on the Navigation Pane

Shutter Bar Open/Close Button

Used to collapse or expand the Navigation Pane

TABL E 1 1 .1

In the first steps in this lesson you opened a database, saved a copy of the database file with a new name, and identified the main elements of the Access window. This process is different from the process used to create copies of Microsoft Office Word, Excel, and PowerPoint files. In each of those applications, you open a file, make changes to it, and then optionally you can save it with a new name, preserving the original fine. When you open an Access files, any changes made are preserved in the original file. If you want to create a new file with a new name, it needs to be done before any changes are made. In this portion of the lesson, you explore the objects in the Personnel database.

To Examine Database Objects

1. In the Navigation Pane, double-click Personnel under the Tables object list. The Table Tools Datasheet tab becomes available on the Ribbon.

The Datasheet view displays the records in the Personnel table. Records contain all of the related facts about a single person, place, object, or event. In this

example, the records contain personnel data. Each record is composed of fields. A field is the smallest useable fact collected for each record. In this example, fields include First Name, Last Name, Home Phone, and Birth Date, to name a few.

Notice that the field names display across the top of the Personnel Table

datasheet, and the data for any particular field displays in a column. The records display in rows. At the bottom of the datasheet are navigation arrows that are used to navigate between records in the table. Notice that there are six records in this table and record 1 is the active record as shown in Figure 11.4.

(6)

UNIT 2: 880 Using Productivity Software

2. In the bar at the bottom of the Personnel table, click the Next record button twice. The record indicator moves to the third record—Margaret

Peacock—which is now the active record. Notice that 3of 6 displays in the navigation record box. The navigation bar displayed at the bottom of the table is also used to navigate records in other objects.

3. Click the First record button; the first record becomes the active record. You can also click the select record box to the left of a record to make it active, or click on the record itself.

4. On the Navigation Pane, click the Shutter Bar Open/Close button to shrink the size of the Navigation Pane. On the Home tab, in the Views group, click the View button. On the Personnel title bar, click the Maximize button. The Table Tools Design tab displays, and the Design view of the table displays as shown in Figure 11.5. The top part of the Table

Design view lists the field names, data types, and any description for the fields. The Field Properties area at the bottom of the table design lists properties for the selected field. The first field listed—EmployeeID—is active by default, and the properties shown on the bottom are the EmployeeID field properties. Properties are characteristics that define a field such as the size of the field. The window control buttons (Minimize, Maximize and Close buttons) for the Personnel table display at the right end of the tab bar.

FIGURE 1 1 .4 Active record

Field names

Navigation bar

Next record button First record button

Number of records in table

(7)

Project 11 Creating A Customized Database UNIT 2: 881 5. Click on each field and observe the change in data type and field

properties for the active field. The data type determines the kind of data that can be entered. The field property options change depending on the data type.

6. Click the Close button at the right end of the tab bar. The Table Design view closes The Navigation Pane for this database remains open, but collapsed at the left side of the window.

7. In the Navigation Pane, click the Shutter Bar Open/Close button, and then click the Objects list arrow to the right of Tables. At the bottom of the displayed list click All Access Objects. The four main object

types—Tables, Queries, Forms, and Reports are listed, with the objects that have been created for each object type displayed underneath. The title on the

Navigation Pane changes from Tables to All Access Objects.

8. On the Navigation Pane, under Forms, double-click PersonnelListing. The PersonnelListing form displays as shown in Figure 11.6. Objects can also be opened right-clicking the object name and then choosing Open from the submenu.

This form is based on the Personnel table and displays the records one at a time in a form. When you look at data in a form, you are looking at the data that is stored in one or more tables. Forms are used to enter and edit records, and are most often designed to view one record at a time. Notice the navigation buttons at the bottom of the form window.

FIGURE 1 1 .5 Shutter Bar

Open/Close button

Field names

Fiel d properties

Data types

Description area

(8)

UNIT 2: 882 Using Productivity Software

9. Click the Close button on the form title bar. In the Navigation Pane, under Queries, double-click Commission. The Commission query displays only three records and three fields as shown in Figure 11.7. Queries are used to search, sort, and limit the data in your tables to display only those records that match specified conditions. Queries enable you to display only those records that answer a specific question, in this case, which employees are paid commission.

Notice the Navigation bar at the bottom of the Query window.

10. On the Home tab, in the Views group, click the View button. The Design view of the Commission: Select Query displays as shown in Figure 11.8, and the Query Tools Design tab is active on the Ribbon. The top portion of the window shows a field list for the Personnel table upon which this query is based. A field list is a box that lists all of the fields in a table or query. The bottom portion of the window is the query grid, which is used to design the query. Here you list the fields you want to include in your query, determine the sort order, and insert a value in one or more of the criteria boxes in order to limit the records displayed.

Notice that Yes displays on the Criteria row under the Commission field.

FIGURE 1 1 .6 Navigation

buttons

First record from the Personnel table is displayed

FIGURE 1 1 .7 Three records

display

Only three fields display

(9)

Project 11 Creating A Customized Database UNIT 2: 883 11. Click the Close button on the Commission title bar to close the

Query window.

12. In the Navigation Pane, under Reports, notice that there are three reports listed. Double-click Commission to display the Commission report. This report is based on the Commission query that you just examined. As you move your mouse pointer over the report, it displays as a magnifying glass.

Reports are always displayed in Print Preview mode, so you see how the report will look when it is printed.

13. Click on the left portion of the line at the bottom of the report. The report is magnified and the current date displays on the bottom of the report. This is part of the formatting that is applied to a report when it is created.

14. Use the vertical and horizontal scroll bars to scroll up and view the three records that are listed.

15. Click the Close button on the QryCommission title bar. Click the Office button and at the bottom of the list click Close Database to close this file but leave the Access program open. The Getting Started with Microsoft Access Window displays.

TO E XTE ND Y OUR K NOWLE DGE … US ING THE V IE W B UTTON

On the Home tab, the View button is used to move between viewing the records and viewing the design of an object. The icon on the button changes between a design icon and a table datasheet, form, or report icon, depending on the currently active object and view. If you are viewing a table datasheet, the icon on the button will display a design icon. This indicates that the Design view will display when the button

FIGURE 1 1 .8 Three fields included in query grid

Field list box for Personnel table

Criteria inserted under Commission field

(10)

UNIT 2: 884 Using Productivity Software

is clicked. Similarly, when you are in the Design view of a table, the View button displays a datasheet icon to indicate that the Datasheet view will display when the button is clicked. The icon on this button similarly changes when you are working with a query, form, or report. Use this button to move between the Design view and viewing the records for each of the objects.

CONTE X TUA L TAB S

When you open an object, a contextual tab may displays. For example, when you open a table, the Table Tools Datasheet tab displays. If you open a form, in the Layout view, the Form Layout Tools Format tab, and Arrange tab display. The contextual tabs change depending on the type of object that is open and the view that is displayed—Datasheet view, Form View, Design View and others. The buttons that are on the tab are related to the active object and the view of that object that is currently displayed. Some of the tabs contain the same buttons.

FIE LD NA ME S

Field names can be up to 64 characters long and include any combination of letters, numbers, spaces, and special characters except a period (.), an exclamation point (!), an accent grave (`), or brackets ([ ]). In many databases, spaces are not used in field names because they can create a conflict when using Microsoft Visual Basic for Applications (VBA), which is the programming language used to write modules in Microsoft Office Access. When spaces are not used for field names it is common practice to capitalize each word in a field name.

LESSO N 2: C re ati n g Ta bl es an d Set tin g F ie ld P ro p ert ies in D esig n Vie w

When you create a table, you name the fields, identify the type of data that each field will contain, set field sizes, and add descriptions if necessary. It is important to ensure that all data entered in a table is accurate. One of the ways you do this is to set field properties, which control the data that is entered and the way the data displays on the screen. Before you create a table in Access, you need to spend some time designing the table. The first step in designing a table is to decide what the table is about: What is the main purpose of the table? Then you identify the fields that should be included in the table and define the data type for each field. The data type determines what kind of data may be entered in a field. It helps ensure that inappropriate data is not entered in a field, such as alphabetic characters in a number field.

Table 11.2 describes the 10 data types that are available.

ACCESS DATA TYPES

DA TA TY PE EXPL A NA TI O N

Text Default data type, used for text and numbers up to 255 characters;

used for numbers that are not in calculations such as phone numbers.

(11)

Project 11 Creating A Customized Database UNIT 2: 885 Memo Used for long text or combinations of text and numbers; up to

63,999 characters or limited by the size of the database.

Number Used for numeric data that may be included in calculations.

Date/Time Date and time values for the years 100 through 9999.

Currency Currency values and numeric data used in mathematical calculations involving data with one to four decimal places.

AutoNumber A unique sequential number incremented by 1 automatically with each new record added to the table.

Yes/No A Yes/No field type limits your data to one of two conditions. You can enter only Yes or No, True or False, or On or Off.

OLE Object Used to insert Object Linking and Embedding (OLE) objects, such as pictures or charts created in another application.

Hyperlink Text or combinations of text and numbers stored as text and used as a hyperlink address.

Attachment Any supported file type may be attached to a table such as images, spreadsheet files, or documents.

Lookup Wizard

A field that allows you to choose a value from another table or from a list of values. Clicking this option starts the Lookup Wizard, which creates a Lookup field.

TABL E 1 1 2

After you have designed the table and decided on the data type for each field, you can add the table to your database. In this lesson, you open an existing database and save it with a new name. The Armstrong Pool, Spa, and Sauna Company created this database to track customer orders and the contractors who will install the products that have been sold. The database already contains a table of contractors who do the installations. You will create the Orders table for this database and set the field properties. The table you create contains information about the orders placed by customers.

To Create Tables

1. Open Access if necessary. In the Open Recent Database pane, click More. Locate and open the AC_1102 database. Click the Office Button, point to Save As, and in the submenu click Access 2000. In the Save As dialog box, navigate to the folder containing your student work and save the file with the name Armstrong.

(12)

UNIT 2: 886 Using Productivity Software

2. On the Security Warning bar, click the Options button, click Enable this content, and then click OK. The Armstrong database uses the Access 2000 file format as indicated in the title bar. The Tables object list displays and Contractors is the only table listed.

3. In the Navigation Pane, under Tables, double-click Contractors to view the contents of this table. This table lists the contractors that are used by the Armstrong Company to install pools, spas, and saunas. It includes

information about each contractor, including a ContractorID field that identifies each contractor with a special ID code. This type of field is called the primary key field, because each ContractorID is unique and cannot be repeated in this table.

4. Close the Contractors table.

5. Click the Create tab, and in the Tables group click the Table Design button. A blank Table Design window displays. Here you enter field names, select the data type, enter a description (if any), and set field properties for each field.

6. With the insertion point in the first Field Name box, type OrderNo

and press R. The first field name is entered, and the insertion point jumps to the Data Type column. The default data type value, text, is displayed. You can also use Tab to move between columns in the Table Design view.

7. Click the arrow in the Data Type box to display the list of available data types, click AutoNumber, and then press R. AutoNumber displays in the Data Type column and the insertion point moves to the Description column. Descriptions are optional. They display on the status bar in the Datasheet view of a table when that field is active. They are used to add clarifying

information to help someone entering or editing data. A description is not needed for this field.

8. Press R to move to the second row of the Field Name column, and type OrderDate; press R, type D to set the data type to Date/Time; press R to move to the Description column and type

Date order was placed. The second field—Date—is added to the table design as shown in Figure 11.9. The first letter of each data type acts like a shortcut key. Pressing the first letter of a data type, as you did here, is a quick way to assign data types when you are setting up a table.

(13)

Project 11 Creating A Customized Database UNIT 2: 887 9. Press R to move to the third line; type CustomerNo and press

R twice. The third field is entered and Text is accepted as the data type. The CustomerNo field is still the active field.

10. In the Field Properties area at the bottom of the window, in the Field Size box, select the displayed value and type 5. This limits the number of characters that can be entered into this field to 5. Because customer numbers are limited to five characters; limiting the field size helps ensure that correct data is entered in this field.

11. Click the next available box in the Field Name column and continue entering the field names, data types, and descriptions as shown in the following table and then compare your results with Figure 11.10:

FIE LD NA ME DA TA TY PE DESCRIPTION

Description Text Description of item purchased

Amount Currency Amount of purchase Installation Yes/No Installation required?

ContractorID Text Installer assigned to job InstallationDate Date/Time Date installation is

scheduled

FIGURE 1 1 .9 Field names

entered

Description added Data type set

(14)

UNIT 2: 888 Using Productivity Software

12. Click anywhere in the OrderNo field to make it the active field, and then on the Table Tools Design tab, in the Tools group, click the Primary Key button. This makes the OrderNo field the primary key field for this table. A small key displays in the field selector box next to the Active indicator arrow. A primary key is used to designate a field that contains unique data for each record. This field is used to help speed up sorting of data and to create a join between tables. A common field is used to join tables so you can retrieve related information from multiple tables. While a primary key is not required, it is strongly recommended. In this table, the OrderNo field will contain unique data because it is an AutoNumber field.

13. On the Quick Access toolbar, click the Save button. In the displayed Save As dialog box, type Orders in the Table Name box, and then click OK. The table is saved and the new name displays in the Table Design view title bar. Leave this window open to continue to the next part of this lesson.

TO E XTE ND Y OUR K NOWLE DGE … UNDE RS TA NDING FILE FORMATS

In previous versions of Microsoft Access, files were not backwardly compatible with earlier versions of the software. With the introduction of Access 2000, file formats became more stable and files created with Access 2000 can be opened and manipulated with Access versions 2002, 2003 and 2007. However, files created with Access versions 2002 or later have to be converted to be viewed with Access 2000. The default file format for your computer may be set to Access 2000, Access 2002 – 2003, or Access 2007. This affects the format of new Access files that you create. The default file format can be changed in the Access Options dialog box on the Office menu. To learn more about Access file formats, click the Help button and type converting Access files in the Search box, press R and then click the link Convert a

FIGURE 1 1 .1 0 Fields added

to table

(15)

Project 11 Creating A Customized Database UNIT 2: 889 database to the Access 2007 file format, and the link Convert an Access 2007 database to an earlier file format.

When you created the Orders table you set one property—the field size property—for the CustomerNo field. You can set properties as soon as you set the data type for a field.

The data type determines the field properties that are available. It is also possible to set field properties after a table is created. Properties can help ensure a consistent look when the data is viewed. For example, text fields can be formatted to display in uppercase letters, or formatted to display phone numbers, social security numbers, and dates with appropriate parentheses, dashes, or slashes. This makes data entry faster because the person entering the data does not have to type those characters. Setting a default value for a field speeds up the input process by having the most common entry for a particular field already inserted. If the Required Field property is set to Yes, it ensures that field is not left empty. In the next part of this lesson, you set properties for a few of the fields in the Orders table.

To Set Field Properties

1. With the Armstrong database open to the Orders Table Design view, click anywhere on the OrderDate field to make it active; click the Input Mask box in the Field Properties area. A small Build button displays to the right of the Input Mask box. Input Masks are used to pre-format a field to make it easier to enter data. For example, in a date field you have to type slashes (/) to separate the month, day, and year. A date input mask pre-formats the field with slashes.

2. Click the Build button to the right of the Input Mask box. The first Input Mask Wizard dialog box opens. The options displayed are related to dates because this is a date/time data-type field.

3. Select Short Date in the Input Mask list, click at the beginning of the Try It box and type 09072008. When you type, you do not have to type the slashes because the input mask formats the date to include them. You must enter two digits for the month and day, so use a 0 in front of values 1 through 9.

Depending how the date is configured for your computer, you may be able to enter the year in a two-digit format rather than the full four-digits.

4. Click Next. In the second Input Mask Wizard dialog box, you can modify the input mask. For example, if you wanted the year to be a two-digit format or a four- digit format, you could change the number of characters shown in the year

placeholder in the Input Mask Text box.

5. Click Finish. The dialog box closes and the input mask displays in the Input Mask box in the Field Properties area as shown in Figure 11.11. Now when you enter a date in this field you will not have to type the slash marks; they have been pre-formatted for this field.

(16)

UNIT 2: 890 Using Productivity Software

6. With the OrderDate field still the active field, click the Default Value box and type Date( ) and then press R. This is a code that displays the current date. Because most orders use the current date, you set the default property for this field to display the current date automatically. The space between the parentheses is removed by the program because it is not needed. When orders are placed, the default date can be overridden by typing another date.

7. Click the InstallationDate field; repeat the procedure in steps 1

through 5 to add a short date input mask to this field; click Yes when prompted to save the table. If a change is made to a table, you have to save the table before the Input Mask Wizard will display. A short date input mask is added to the InstallationDate field.

8. Click the CustomerNo field, and then, in the Format property box, type >. The data you will enter in this field starts with a letter, followed by a dash and numbers. The > (greater than) symbol is used to force any letters in this field to display as uppercase.

9 Click the Required property box for the CustomerNo field; click the list arrow in the Required box and select Yes. This property ensures that the CustomerNo field will not be left empty.

10. Click the ContractorID field; change the Field Size property to 4 and type > in the Format property box. This limits the field size to match the size of the Contractor ID numbers that are used, and formats it to display any letters as uppercase.

11. On the Quick Access toolbar, click the Save button to save the

changes you have made to the Orders table and then close the table.

The changes to the Orders table are saved. Leave the Armstrong database open for the next lesson.

FIGURE 1 1 .1 1 OrderDate is the

active field

Short date input mask

Build button

(17)

Project 11 Creating A Customized Database UNIT 2: 891 TO E XTE ND Y OUR K NOWLE DGE …

CHA NGING A TA B LE A FTE R IT CONTA INS DA TA

You can make changes to a table at any time. However, if you change field properties, or delete fields after data has been entered, warning boxes may display when you attempt to save the changes. For example, if you change a field size to a smaller number, Access recognizes the smaller field size and warns you that some data may be lost. Therefore, it is important that you are certain that the smaller field size will not be a problem. Another warning box displays if you add a required field property. The addition of a required field invokes a "data integrity rules have changed" warning. If one of the records does not contain the required data, Access cannot enforce the required field property.

LESSO N 3: C re ati n g R el ati o nshi ps a n d Enf o rcin g Ref e re nti al I nt eg rity

Microsoft Office Access is a relational database, which means the data is divided into several tables that can be related to each other by a common field. When this is done correctly, it minimizes the amount of data that needs to be stored. In the Armstrong database, the information about each contractor is entered once, rather than being repeated for every order. The ContractorID field, which is designated as the primary key, is used to uniquely identify each contractor. The ContractorID is also in the Orders table, which identifies the contractor assigned to install the order. You create a relationship between the Contractors table and the Orders table based on this common field.

A relationship is a join—connection— between two tables based on a common field for the purpose of displaying or extracting information from connected records in both tables. Relationships between tables are formalized in the Relationships window. Here you define the relationship to ensure that a proper relationship is established before you attempt to create forms or reports that use fields from more than one table. This is particularly important in complex databases with many tables.

The most common type of relationship is the one-to-many relationship. In a one- to-many relationship, a record in one table may be related to many records in another table. In the Armstrong database, each contractor has been assigned many orders. In other words, each ContractorNo appears once in the Contractors table, but may appear multiple times in the related Orders table.

A one-to-one relationship exists between two tables when a record in one table is related to a single record in a second table. This is most often used when data is placed in a separate table because access to the information is restricted.

In this lesson, you use the Relationships window to create a one-to-many relationship between the two tables in the Armstrong database.

(18)

UNIT 2: 892 Using Productivity Software

To Create a Relationship

1. With the Armstrong database open, click the Database Tools tab, and in the Show/Hide group click the Relationships button. The

Relationships window opens and the Show Table dialog box displays as shown in Figure 11.12. The Show Table dialog box is used to add field list boxes to the Relationships window. The Relationship Tools Design tab displays in the Ribbon.

If you hav e pro blems...

If the Show Table dialog box does not open on your screen click the Show Table button in the Relationships group on the Relationship Tools Design tab.

2. With the Contractors table already selected, hold down C and click Orders. Click Add in the Show Table dialog box, and then close the Show Table dialog box. Table field lists are added to the Relationship window.

To make it easier to see all of the fields listed, you can expand the field list boxes by dragging the lower edge of the box.

3. Move the mouse pointer to the lower edge of the Contractors field list box until you see a two-headed arrow, drag down to expand the field list box so you can see all the fields.

4. In the same manner expand the Orders field list box until you see all of the fields. ContractorID is in both field list boxes. In the Contractors

FIGURE 1 1 .1 2

Relationship Tools Design tab

Relationship window

Show Table button

Tables display in the Show Table dialog box

(19)

Project 11 Creating A Customized Database UNIT 2: 893 table, the primary key indicator displays next to the field name. In the Orders table, ContractorID does not display the primary key indicator because here it is not the primary key field; rather it was included for the purpose of creating a join, or relationship with the Contractors table. A field used for this purpose is known as the foreign key field—the common field that is used to join with a primary key field in another table.

5. In the Contractors field list, drag the ContractorID field from the Contractors table and drop it on the ContractorID field in the Orders table. The Edit Relationships dialog box displays as shown in Figure 11.13.

Access determines that this is a one-to-many relationship because the

ContractorID field used to create the join is a primary key field in only one of the two tables.

6. Click the Enforce Referential Integrity check box to select it.

Enforcing referential integrity helps you maintain the integrity of your database. It prevents you from assigning an order to a nonexistent contractor. It also means that you cannot drop a contractor from your database until all of their assigned installations are reassigned to other contractors.

7. Click Create. The dialog box closes and a join line displays, as shown in Figure 11.14. The number 1 shows next to the one side of the relationship and the infinity symbol, , shows next to the many side of the relationship. These symbols indicate that referential integrity is enforced.

FIGURE 1 1 .1 3 Primary table

displays on the left

Related table displays on the right

Relationship identified

(20)

UNIT 2: 894 Using Productivity Software

8. Close the Relationships window; choose Yes when you are prompted to save the changes to the layout. Leave the Armstrong database open for the next lesson.

TO E XTE ND Y OUR K NOWLE DGE …

RE QUIRE ME NTS FOR CRE A TING RELA TIONS HIPS

To create a relationship between two fields, not only must the fields contain the same data, but they must also use the same data type. It is not necessary, however, that related fields have the same name. If the primary field is an AutoNumber data type, the related field must use the Number data type with the Field Size property set to long integer to match the format of the AutoNumber data type.

LESSO N 4: A d din g an d De let in g R eco rds

Data can be entered into the database in three different ways: it can be imported from another source, it can be captured from a Web site, or it can be entered using the keyboard. With customized databases, this last method is the most common. Records can be entered directly into a table or by using an Access form based on the table. You can also delete records using either an Access form or directly in the table.

In this lesson, you enter data directly into the Orders table and then delete a record from the Contractors table.

FIGURE 1 1 .1 4 One side of

relationship

Many side of relationship Join line

(21)

Project 11 Creating A Customized Database UNIT 2: 895 To Add and Delete Records

1. On the Navigation Pane, double-click the Orders table, and then click the Maximize button on the Orders title bar. The table datasheet fills the window. The field names display across the top of the table, but no data has been entered yet. The first field is an AutoNumber field, which means that the program will assign a sequential number as soon as anything is entered into any fields in the first row. The second field shows the current date because the default value

property was set to display the current date for this field.

2. Press F to move to the Date field; type 05122005 and press F. A new date is entered, 1 appears in the OrderNo field and the insertion point moves to the CustomerNo field. You did not have to type the slashes in the date field because of the short date input mask property that was added to this field. The F key is used to move across a row between fields. To move back a field, press

S + F. Notice that a pencil icon displays in the record selector box, which indicates that this record is being edited.

3. Type t-241 in the CustomerNo field box and then press F; type

15x30 pool, press F, type 3500 and press F. Data is entered in the next three fields. Notice that the t in the CustomerNo field is automatically changed to an uppercase letter and that the amount in the currency field displays with a dollar sign and two decimals. These changes are the result of the format property (>) set for the CustomerNo field and the data type (currency) set for the Amount field.

4. Press s. A check mark is added to the box in the Installation field. Using the spacebar is a quick way to choose Yes for this field. If you skip over this field and leave it blank, it is interpreted as No. You can also click the box to select Yes. 5. Press F, type oh-3, press F, type 05242005. The first record is

added to the Orders table as shown in Figure 11.15. Notice that the ContractorID data changes to uppercase letters and slashes display between the month, day, and year in the InstallationDate field. Again, these formatting changes are the result of the format property (>) set for the ContractorID field and the input mask set for the InstallationDate field.

FIGURE 1 1 .1 5 AutoNumber of first

record

Pencil icon indicates record is being edited

New record button

New record button

Record entered in first row

(22)

UNIT 2: 896 Using Productivity Software

6. Click the New (blank) record button on the Navigation bar. The insertion point moves to the first field in next row in the table. There is a New Record button on the navigation bar and on the Home tab, in the Records group (refer to Figure 11.15). In this case, you could also have simply pressed R to move from the first row of the table to the empty row in order to add a new record.

Records are added or updated to the database as soon as you move the insertion point off the record that you are editing. So, in this example, the act of clicking the New Record button also caused the first record to be recorded in the table.

7. Press F to move to the Date field, and follow the same procedure to enter the next four records shown in the table below.

Ord er N o Date Cu st ome r No Desc rip tio n Amo un t In st allati o n Co nt ract o rID In st allati o nDat e

2 05/12/2005 C-182 8 person spa $4,000.00 Yes OH-2 05/22/2005

3 05/13/2005 C-183 12x24 pool $1,695.00 Yes OH-2 05/25/2005

4 05/13/2005 Y-675 4 person spa $2,300.00 No

5 05/14/2005 S-737 15x24 pool $2,450.00 Yes MI-1 05/28/2005

Records are automatically saved as soon as you move to the next record. When you close the Orders table, the last record you entered is saved. In Access, you do not have to specifically save records; they are saved as soon as you close the table, move to another record, or change views. If you want to specifically save a record, on the Home tab, in the Records group you can click, Save, or press S + R. Compare your results with Figure 11. 16.

8. Click the Office button, point to Print and then in the submenu click Print Preview. On the Print Preview tab, in the Page Layout group click the Landscape button. The Print Preview tab is used to control the margins and the orientation of the page. These setting have to be chosen each time you want to print. Notice that the name of the table and the date display in the header, and the page number display in the footer area. These are automatically set by Access. The name of the table is the only portion of the header and footer area that you can control.

9. On the Print Preview tab, in the Print group, click Print and then click OK.

10. Close the Print Preview window. On the right end of the Tab bar, click the Close Window button to close the Orders table.

FIGURE 1 1 .1 6 Four more

records added

(23)

Project 11 Creating A Customized Database UNIT 2: 897 11. Open the Contractors table. Click the record selector box to the left

of the sixth record, Hatfield's. The record is selected.

12. On the Table Tools Datasheet tab, in the Records group, click the Delete button. A warning box displays advising you that if you delete this record you will not be able to undo the operation as shown in Figure 11.17.

13. Click Yes. On the right end of the Tab bar, click the close button to close the Contractors table. The record is removed from the table and only the Navigation Pane displays the two tables for this database. Leave the

Armstrong database open for the next lesson.

TO E XTE ND Y OUR K NOWLE DGE … E DITING RE CORDS

Records in Access are edited using the same techniques as you use to edit text in other Microsoft Office applications. Press B to remove characters to the left, or press X to remove characters to the right. If you need to return to the previous field, hold down S and then press F. While you hold down the S key, you can continue to press F to move backward through the fields. You can also click to place the insertion point in a field, and then drag to select the text you want to replace. If you start to make a change and want to undo it, press E before you leave the field, and the original data will display. 2can be used like a toggle button to select the entire field or move the insertion point to the end of the field.

LESSO N 5: C re ati n g a Fo rm Usin g t he Fo rm Wiza rd

Forms are used to enter data and to view records, usually one at a time. With a form, more fields can be displayed on the screen at a time than when you view records in a table datasheet. You can create an AutoForm, which displays all the fields of a table in a column form layout. The Forms Wizard enables you to customize a form. With the Form

FIGURE 1 1 .1 7 The record for

OH-1 Hatfield is removed from the table

Message box warns that this change will be permanent

(24)

UNIT 2: 898 Using Productivity Software

Wizard you can list fields in an order that is different from the table, include only the fields you need, select the layout, and apply a design.

In this lesson, you use the Form Wizard to create a customized form based on the Contractors table.

To Create a Form Using the Form Wizard

1. With the Armstrong database open, in the Navigation Pane, click the Objects List arrow and then click Forms. Forms displays as the active object and no forms are shown for this database.

2. On the Ribbon click the Create tab. In the Forms group, click More Forms and then click Form Wizard. The first Form Wizard dialog box displays. Here you select the table or query you want to use for your form and the fields to include. The order in which you select the fields determines the order the fields will be displayed on the form. The Contractors table displays in the

Tables/Queries box and the fields from that table are listed in the Available Fields box as shown in Figure 11.18.

3. Click the Move All Fields arrow to place all of the fields from the Contractors table in the Selected Fields box, and then click Next. The second Form Wizard dialog box prompts you to choose a layout for the form.

4. Choose Columnar, if necessary. This will display each record in a columnar format, as shown in the preview at the left side of the dialog box.

5. Click Next, and then click Office for the style. The third Form Wizard dialog box is used to select a background style for the form. A preview of the selected style displays on the left side of the dialog box.

6. Click Next and type Contractors Form. In the fourth (and final) Form Wizard dialog box you name the form.

FIGURE 1 1 .1 8 Fields in the

contractor table

Selected Fields box

Selected table

Move arrow

Move All fields arrow

(25)

Project 11 Creating A Customized Database UNIT 2: 899 7. Be sure that the Open the form to view or enter information option

button is selected and then click Finish. The completed form is saved and displays the first record from the Contractors table as shown in Figure 11.19.

8. In the first record for ContactorID IN-1, select Marci White in the Contact Name field and type your name. This replaces the contact person for REC Services in the Contractors table.

9. O n th e H o m e t a b, i n t h e V i e w s g ro u p c l i c k t h e V i e w b u tt o n a rr o w and then click Design View. The Form Design view displays as shown in Figure 11.20. Here you can change the layout of the form by moving the controls, resize or add controls, or change the design that you selected. A control is any graphical object on a form or a report that is used to display data, perform an action, or make a form or report easier to read. The Form Design Tools contextual tabs—Design and Arrange—are available in the Ribbon. The tools shown here are used to work with the design, format and layout of forms. Similar tools are

available when you work with a report design.

FIGURE 1 1 .1 9

(26)

UNIT 2: 900 Using Productivity Software

10. On the Contractors Form title bar, click the Close button to close the form. The form closes and the Contractors Form is listed on the Navigation Pane.

LESSO N 6: C re ati n g a R ep ort Usi ng t he R ep o rt W iza rd

Printed reports are useful for sharing data in a meeting, or to show information at a point in time. Reports can also be used onscreen to summarize, group, and list data from selected fields. A report gives you the flexibility to print the records and fields you select.

You can also sort and group the records in a number of different ways. The Access Report Wizard helps you create a customized report that includes the fields you want, grouped and sorted in the manner you select. Reports, like forms, can be modified once they have been created.

In this task, you create a contact list report based on the Contractors table. It will be grouped by state and sorted by the contractors' names

To Create a Report Using the Report Wizard

1. With the Armstrong database open, in the Navigation Pane, click the Objects List arrow and then click Reports. No reports are listed for this database.

2. Click the Create tab. In the Reports group, click the Report Wizard button. The first page in the Report Wizard opens and the Contractors table displays in the Tables/Queries box with its fields displayed in the Available Fields list box. Using the Report Wizard is similar to using the Form Wizard. You select the fields you want to include and then add them to the Selected Fields box.

3. Doub le -c li ck on ea ch of t he fol lo wi ng f iel ds t o ad d th em to t he Sel e cte d Fi e lds b ox: Co ntr actorN am e, Con ta ct Nam e,

Stat eOrPr ov in ce, Pho ne Num ber, F a xN umbe r. Five fields move to the

FIGURE 1 1 .2 0 Controls

that display labels

Controls that display data Form

Design Tools tabs

(27)

Project 11 Creating A Customized Database UNIT 2: 901 Selected Fields box as shown in Figure 11.21. A field is moved by double-clicking on the desired field or by selecting the field and clicking the Move arrow.

4. Click Next. In the box on the left of the screen, click the

StateOrProvince field and then click the Move arrow. The second

Report Wizard dialog box is used to group data. This report will be grouped by the StateOrProvince field. This mean that all of the records for the same state or province will be displayed together as a group with the specific state or province name displayed as a heading at the beginning of those records and the other fields listed underneath, as shown in Figure 11.22. In a report, you may want to organize records by one or more fields.

FIGURE 1 1 .2 1 Contractors

table selected

Fields added

FIGURE 1 1 .2 2 Field names

entered

Records grouped by StateOrProvince

Other fields include in report

(28)

UNIT 2: 902 Using Productivity Software

5. Click Next; in the third Report Wizard dialog box click the list arrow at the right end of box 1 and select ContractorName. You can sort the data in a report on up to four fields. The button to the right of the sort box indicates the sort order is ascending—A to Z. Clicking this button would change the sort order to descending—Z to A.

6. C l i c k N e x t; in t h e f o ur t h R e p or t W i z ar d d i a l o g b o x s e l e c t th e

S t e p p e d l a y o ut an d t h e P or tr a i t o ri e n ta t i o n , i f n e c es s ar y . This dialog box is used to select the report’s layout and orientation—portrait or landscape.

7. Click Next; in the fifth Report Wizard dialog box choose Office for the report design. The design you selected is shown in the preview area.

8. Click Next; in the sixth and final Report Wizard dialog box type

Contact List as the report name.

9. Click Finish. On the Quick Access toolbar click the Save button to save the report. The Contract List report displays in Print Preview as shown in Figure 11.23.

10. On the Print Preview tab, in the Print group click the Print button and then click OK. Close the Contact List report. On the Contract List title bar, click the Close button.

11. Click the Office button and then click Close Database. Close Access.

SUMMAR Y

In this project, you were introduced to Access, the Microsoft Office relational database program that manages collections of related data. You learned the function of the four main objects in Access: tables that store the data; queries, which are used to sort, search, and limit the data; forms, which are used to enter or edit records; and reports, which summarize information in a meaningful manner. You examined the manner in which data

FIGURE 1 1 .2 3 Report is grouped by

StateOrProvince field

Records sorted by Contractor under each state

References

Related documents

The expansion of aquaculture and the recent development of more intensive land-based marine farms require commercially-valuable halophytic plants for the treatment

The absolute magnitude of the difference between the average and this data point can be used as a rather conservative error estimate which includes all the data within error

Vesiculovirus life cycle can be divided into discrete steps, namely, adsorption of virus particle, penetration of virus into cell, uncoating and release of core RNP into the

Reptilen badar, urinerar och defekerar gärna i vattenskålen så regelbundna byten krävs för att inte föroreningarna skall orsaka sjukdom (Girling, 2013).. Eventuella vitamin- och

insurrections of the declaration freedom tower held in another government and not written by email address or basic function of the depository of the accommodation of

All records for LASIK procedures from one single cen- ter without patient identifiers were extracted from the Optical Express electronic medical record system using the

○ If BP elevated, think primary aldosteronism, Cushing’s, renal artery stenosis, ○ If BP normal, think hypomagnesemia, severe hypoK, Bartter’s, NaHCO3,

The described setup of the LPS learning factory allows the simulation of different kinds of learning modules within a real-world manufacturing environment, hence offering a