• No results found

Database Concepts 3.5

N/A
N/A
Protected

Academic year: 2021

Share "Database Concepts 3.5"

Copied!
47
0
0

Loading.... (view fulltext now)

Full text

(1)

Database Concepts 3.5

David M. Kroenke and David J. Auer

THE ACCESS WORKBENCH

Section 1

(2)

“The Access Workbench” is designed to reinforce the concepts you learn in each chapter. Additionally, you will learn many Microsoft Access skills by following along on your computer. In this section of “The Access Workbench,” we’ll review some database basics from Chapter 1 as we learn the basic steps necessary to build and use Access database applications.

As discussed in Chapter 1, Microsoft Access is a personal database that combines a DBMS with an application generator. The DBMS performs the standard DBMS functions of database creation, processing and administration, while the application generator adds the abilities to create and store forms, reports, queries, and other application-related functions. In this section, we will work with only one table in a database; in the next section, we will expand this to include two or more tables.

The Microsoft Office Fluent User Interface

Microsoft Access 2007 uses the Microsoft Office Fluent user interface found in most (but not all) of the Microsoft Office 2007 applications. This user interface is also described in detail in this section, and, unfortunately, that discussion will make this section of “The Access

(3)

Creating an Access Database

The first step is to create the Access database that will store the database tables and the application forms, reports, and queries. In this section, we will work with a single table, form and report—we will leave queries for a later section.

Our Access database will be used by a car dealership named Wallingford Motors, which is located in the Wallingford district of Seattle, Washington. Wallingford Motors is the dealer for a new line of hybrid cars named Gaea.1

Instead of using only a gasoline or diesel engine, hybrid cars are powered by a combination of energy sources, such as gasoline and electricity. Gaea produces the following four models:

1. SUHi The Sport Utility Hybrid (Gaea’s answer to the SUV) 2. HiLuxury A luxury class four-door sedan hybrid

3. HiStandard A basic four-door sedan hybrid

4. HiElectra A variant of the HiStandard that uses a higher proportion of electrical power

There is an increasing interest in hybrid cars—and specifically in the Gaea product line. The sales staff at Wallingford Motors needs a way to track its customer contacts. Therefore, our database application will be a simple example of what is known as a customer relationship management system (CRM). A CRM is used (among other uses) by a sales staff to track current, past, and potential customers as well as the sales staff’s contacts with these

customers. We will start out with a personal CRM used by one salesperson and expand it into a companywide CRM in later sections.2

We will name our Access application and its associated database WMCRM.

1

(4)

Creating the Access Database WMCRM

1. Click Start | All Programs | Microsoft Office | Microsoft Access 2007. The Microsoft Access 2007 window appears as shown in Figure AW-1-1. Note that Getting Started with Microsoft Office Access page is displayed in the Microsoft Access window along with a set of Template Categories panes.

NOTE: The menu command or icon location used to start Microsoft Excel 2007 may vary

depending on the operating system you are using and how Microsoft Office is installed on the computer you are using.

Figure AW-1-1— The Microsoft Excel 2007 Window

NOTE: Microsoft Access 2007 is used in these sections, and the wording of the steps and

appearance of the screenshots reflect its use. If you have a different version of Access, there will be some differences in the step details and in what you see on screen. However, the basic functionality is the same, and you can complete “The Access Workbench” operations in any version of Access.

(5)

Figure AW-1-2 — The Blank Database Pane

3. Type in the database name WMCRM.accdb in the File Name text box, and then click the

Create button.

NOTE: The database will be created in your My Documents folder. If you want to create

the database in a different folder, use the Open button shown in Figure AW-1-2 to browse to the correct location.

4. The new database appears as shown in Figure AW-1-3 on the next page. The Microsoft Access window itself is now named WMCRM: Database (Access 2007)—Microsoft

Access to include the database name. Note that since this is a new database, Access

2007 has assumed that you will want to immediately create a new table. Therefore, a new table named Table1 is displayed in Datasheet view in the Document window. We do not want this table open at this time, so click the Close Document button shown in Figure AW-1-3 on the next page.

5. The Access 2007 window with the new database appears as shown in Figure AW-1-4 on the next page. Most of the new features of the Microsoft Office Fluent user interface can be seen in this window.

The Blank Database pane Type the database name WMCRM.accdb here

If you don’t want the database to be created in My Documents, use the Open button to browse to the desired location

The Create

(6)

Figure AW-1-3 — The New Access Database The database name WMCRM: Database (Access 2007) The Document Window using the tabbed documents interface The Close Document button The Microsoft Office button The Quick Access Toolbar The tabbed Ribbon

The Close [Exit]

button

The Document

Window

The object

Navigation Pane

(7)

The Microsoft Office Fluent User Interface

The Microsoft Office Fluent User Interface as used in Access 2007 has the following features:

 The Microsoft Office Button

 The Quick Access Toolbar

 The Ribbon

 Contextual command tabs

 Galleries

 Tabbed documents

 The Navigation Pane

 The Shortcut Menu

 The Status Bar

 The Help System

The Microsoft Office Button

The Microsoft Office Button is used to display the File Menu, as shown in Figure AW-1-5 on the next page. The File Menu for Access contains the New, Open, Save, Save As, Print, Manage, E-mail, Publish and Close Database commands. Moving the mouse pointer over a command that has options (indicated by the arrowhead to the right of the command) will display those

options—as shown in Figure AW-1-6 on the next page. There, the options for the Manage command are displayed.

The File Menu also contains Access Options and Exit Access buttons. Clicking the Access

(8)

Figure AW-1-5 — The Microsoft Office Button and the File Menu

The Microsoft

Office Button

The File Menu A File Menu command followed by an arrowhead has multiple options A File Menu command followed by an arrowhead has multiple options

Move the mouse pointer over the command to display the

(9)

Figure AW-1-7 — The Access Options Dialog Box

The Quick Access Toolbar

As shown in Figure AW-1-4, Access contains a Quick Access Toolbar. By default in all Office 2007 applications, the Quick Access Toolbar contains three buttons: Save, Undo, and Redo. However, the Quick Access Toolbar can be customized.

Here, we’ll again modify it to include a Quick Print button and a Print Preview button. To do this, we’ll use the Customize Quick Access Toolbar drop-down list as shown in Figure AW-1-8 on the next page. By selecting or de-selecting items on this list, we can easily modify the icons on the Quick Access Toolbar. This is the quick way to modify the toolbar, but if we need more detailed control over the icons on the Quick Access Toolbar, selecting More Commands… on the drop-down list will take us to the Customize settings page of the Access Options dialog box.

(10)

Figure AW-1-8 — The Customize Quick Access Toolbar Drop-Down List

Modifying the Access Quick Access Toolbar

1. Click the Quick Access Toolbar drop-down arrow button. The Customize Quick Access Toolbar Drop-Down List appears.

2. Click Quick Print. The Quick Print button is added to the Quick Access Toolbar.

3. Click the Quick Access Toolbar drop-down arrow button. The Customize Quick Access Toolbar Drop-Down List appears.

4. Click Print Preview. The Print Preview button is added to the Quick Access Toolbar. 5. The Access application window now appears as shown in Figure AW-1-9 on the next

page.

The Ribbon

The tabbed Ribbon, or just Ribbon, shown in Figure AW-1-4 is the main Access 2007 command interface. The interface uses a set of command tabs (and the Microsoft Office Button discussed earlier) to access tools that are located on the associated ribbons as groups of related

commands. Each Office 2007 application has a Home tab and a set of additional tabs specific to each application. The default Access command tabs are the Home, Create, External Data, and Database Tools tabs. There tabs are shown with their related ribbons in Figure AW-1-10 on

(11)

Figure AW-1-9 — The Quick Print and Print Preview Buttons on the Quick Access Toolbar

In each ribbon, the currently available commands are shown in color, and the unavailable commands are shown in grey. We will discuss the various commands in each ribbon as needed, so for now we’ll just become familiar with each command tab and its associated ribbon.

Figure AW-1-10A — The Access Home Command Tab and Ribbon

Figure AW-1-10B — The Access Create Command Tab and Ribbon

The modified

Quick Access Toolbar with two

additional icons The Quick Print

(12)

Figure AW-1-10C — The Access External Data Command Tab and Ribbon

Figure AW-1-10D — The Access Database Tools Command Tab and Ribbon

The Contextual Tabs and Ribbons

In addition to the basic command tabs and ribbons, some Office 2007 applications including Access have additional contextual tabs and their associated ribbons. These will be displayed as needed depending on the task we are doing. While we will discuss these as we encounter them, you can see an example in Figure AW-1-3, where the Table Tools contextual tab is shown along with the Datasheet ribbon.

Galleries

A gallery is a control or command that appears on a ribbon and shows the results of a

(13)

Viewing an Access 2007 Gallery

1. Click the Create command tab. The Create ribbon is displayed as shown in Figure AW-1-11 on the next page.

Figure AW-1-11 — The Create Ribbon

2. Move the mouse over the Table Templates button. The Tables Templates button is displayed with a golden background, and after a few seconds a text box describing the function of the Table Templates button is displayed as shown in Figure AW-1-12.

Figure AW-1-12 — The Table Templates Button

3. Click the Table Templates Gallery Drop-Down Arrow to display the Table Templates Gallery. As shown in Figure AW-1-13 on the next page, a gallery of five templates for Access database tables is provided—a table template is a predefined table intended to help the user create commonly used database tables.

(14)

Figure AW-1-13 — The Table Templates Gallery

4. Press the Esc key to clear the gallery, and then click the Home tab to display the Home ribbon.

Database Objects and the Navigation Pane

Microsoft uses the term object as a general name for the various parts of an Access database. Thus, a table is an object, a report is an object, a form is an object, and so on. Access objects are displayed in the Access Navigation Pane shown in Figure AW-1-4. However, since we have not created any objects in the WMCRM database, the Navigation Pane is currently empty. However, the Navigation Pane shown in Figure AW-1-4 is labeled as All Tables, which means that only database tables and their related views will be shown, since we will want to be able to see all Access objects (i.e., tables, forms, reports, etc.) in the Navigation Pane as we create them.

To see how objects are selected for display in the Navigation Pane, we’ll set it to show all Access objects.

Selecting Objects in the Access 2007 Navigation Pane

1. Click the Navigation Pane drop-down list arrow button in the upper right corner of the Navigation Pane. The Navigation Pane All Tables drop-down list appears as shown in Figure AW-1-14 on the next page.

The Table

(15)

Figure AW-1-14 — The Navigation Pane Drop-Down List

2. Click Object Type in the Navigation Pane drop-down list, and then click the Navigation

Pane drop-down arrow button again. The Navigation Pane drop-down list now appears

as the Navigation Pane All Access Objects drop-down list shown in Figure AW-1-15.

Figure AW-1-15 — The All Access Objects Drop-Down List

3. As shown in Figure AW-1-16 on the next page, the Navigation Pane for All Access The Navigation

Pane drop-down list arrow button

The All Tables

drop-down list

The All Access

(16)

Figure AW-1-16 — The Empty Navigation Pane

Also note that if we need to we can hide the Navigation Pane by clicking the Shutter Bar Open/Close Button (the left-facing double chevron button) on the upper right corner of the Navigation Pane shown in Figure AW-1-16. If we click the button, the Navigation Pane shrinks to a small band labeled Navigation Pane on the right side of the Access 2007 window. The band will then show the Shutter Bar Open/Close Button as a right-facing double chevron button that is used to restore the Navigation Pane when we need to use it again.

Shortcut Menus

The shortcut menu is a context sensitive tool. It is accessed by right-clicking an object or a point in a document window or the Navigation Pane.

Displaying the Shortcut Menu

1. Right-click anywhere in the Navigation Pane. The shortcut menu appears as shown in

Figure AW-1-17 on the next page. Note that there are many options and actions easily accessible through the shortcut menu. We will discuss these when we use them. 2. Press the Esc key to close the shortcut menu.

The Shutter Bar

Open/Close Button—use this

(17)

Figure AW-1-17 — The Shortcut Menu

The Status Bar

As shown in Figure AW-1-18 on the next page, the status bar appears at the bottom of the Access window. It displays information regarding the current state of Access. In Figure AW-1-18, it shows Access in Ready mode, which means that Access is expecting the user to take some action.

The Help Button

The Help button—the full name is the Microsoft Office Access Help button—shown in Figure AW-1-18 on the next page is used to open the Access Help window. This window has a search function that allows us to search for information about Access.

By The Way

You can also display the Access Help window by pressing the F1 button. This is a Windows standard used in most Windows applications—press F1 for help!

The Shortcut

(18)

Figure AW-1-18 — The Status

The Close [Exit] Access Button

The Close button shown in Figures AW-1-4 and AW-1-18 is actually a close and exit button— clicking it will close the active database and then exit the Access program. Note that Access actively saves most changes to a database and will prompt you with Save command requests when they are needed. For example, when you close a table with modified column widths, Access will ask you if you want to save the changes in the table layout. Therefore, we do not need to save Access databases the way we save Word documents and Excel workbooks. We can simply close the database, knowing the Access has already saved all critical changes since we opened it.

The Close [Exit]

button

The Help button The Status

Bar—Access in

(19)

Closing the Database and Exiting Access

1. Click the Close button. The database is closed and the Access program is exited.

By The Way

You can also simultaneously close the database and exit Access by double-clicking the Microsoft Office

Button. To close just the database while leaving Access itself open, use the File menu Close command.

When to Take a Break

While we’re working through the sections of “The Access Workbench,” we may want to stop and take a break in the middle of a section. If we do, we need to close the database we’re working with and exit Access. Then, when we’re ready to do some more work, we’ll start Access and open our database.

Since we currently have closed our database and exited Access, now is a good time to take a break if you want to!

Opening an Existing Access Database

Earlier in this section of “The Access Workbench,” we created a new Access database for the Wallingford Motors CRM (WMCRM.accdb). We then closed the database and exited Access. Before we can continue building this database, we need to start Access and open the

WMCRM.accdb database.

When we open an existing database, Access 2007 gives us the option of using Access security options to shut down certain Access 2007 features in a database to protect ourselves against harm not only from viruses but from other possible problems. Unfortunately, the Access 2007 security options also shut down significant and needed operational features of Access.

(20)

Opening a Recently Opened Access Database

1. Open Access by clicking Start | All Programs | Microsoft Office | Microsoft Access

2007. Access is displayed as shown in Figure AW-1-19.

Figure AW-1-19 — The Open Recent Database Pane

2. As shown in Figure AW-1-19, the database file name WMCRM.accdb is listed in the

Open Recent Database pane.

3. Click the Microsoft Office Button to display the File Menu, as shown in Figure AW-1-20 on the next page. Note that the database file name WMCRM.accdb is listed in the

Recent Documents pane.

4. We can open the database by clicking on either entry. Since the File Menu is open, click the WMCRM.accdb file name in the Recent Documents pane to open the database. 5. A Security Warning bar appears with the database as shown in Figure AW-1-21 on the

(21)

Figure AW-1-20 — The Recent Documents Pane in the File Menu

Figure AW-1-21 — The Security Warning Bar

6. Click the Security Warning Options… button to display Microsoft Office Security

Options dialog box as shown in Figure AW-1-22 on the next page.

(22)

Figure AW-1-22 — The Microsoft Office Security Options Dialog Box

Now we can start building the WMCRM database. For use by one salesperson, we only need two tables in the WMCRM database: CUSTOMER and CONTACT. We’ll create the CUSTOMER table first.

The CUSTOMER table will contain the columns shown in the table in Figure AW-1-23. The table shows the column name and characteristics for each column. The column characteristics are: type, key, required, and remarks.

Figure AW-1-23 — Database Column Characteristics for the CUSTOMER Table

Type refers to the kind of data that the column will store. Some possible Access data types are shown in Figure AW-1-24 on the next page. For CUSTOMER, most data is being stored as text

The Microsoft

Office Security Options dialog box

Click the Enable

this content radio button

(23)

numbers, and symbols (a space is considered a symbol). The number behind the word Text indicates how many characters may be stored in the column. For example, customer last names may be up to 25 characters long. The only number or numeric data column in the CUSTOMER table is CustomerID, which is listed as AutoNumber. This indicates that ACCESS will automatically provide a sequential number for this column for every new customer that is added to the table.

Figure AW-1-24 — Microsoft Access 2007 Data Types

Key refers to table identification functions assigned to the column. These will be described in detail in Chapter 2, “The Relational Model.” At this point, you simply need to know that a primary key is a column value used to identify each row and, therefore, the values in this column must be unique. This is the reason for using an AutoNumber data type, which automatically assigns a unique number to each row in the table as it is created.

Required refers to whether or not the column must have a data value. If Yes, a value must be present in the column. If No, the column may be blank. Note that since CustomerID is a primary key used to identify each row, it must have a value.

(24)

computer-generated unique numbers used to identify rows in a table (i.e., a primary key). This is done by using the Access AutoNumber data type.

Creating the CUSTOMER Table

1. Click the Create command tab to display the Create Ribbon. 2. Click the Table Design button as shown in Figure AW-1-25.

Figure AW-1-25 — The Table Design Button

3. The Table1 tabbed document window is displayed in Design view as shown in Figure AW-1-26 on the next page. Note that along with the Table1 window, a contextual tab named Table Tools is displayed, and that this tab adds a new command tab and ribbon named Design to the set of command tabs displayed.

NOTE: It seems like now would be a good time to name the new table CUSTOMER. With

Access, however, you don't name the table until you save it the first time, and you can’t save the table until you have at least one column defined. So, we will define the columns, and then we will save and name the table. If you want, save the table after you've defined just one column. This will close the table, so you’ll have to reopen it to define the remaining columns.

4. In the Field Name column text box of the first line, type the column name CustomerID, and then press the Tab key to move to the Data Type column. (You can also click the Data Type column to select it.)

NOTE: The terms column and field are considered synonyms in database work. The

term attribute is also considered to be equivalent to these two words.

5. Select the AutoNumber Data Type for CustomerID from the Data Type drop-down list as shown in Figure AW-1-27 on the next page.

(25)

Figure AW-1-26 — The Table1 Tabbed Document Window

Figure AW-1-27 — Selecting the Data Type

The Table Tools

contextual tab is

displayed along with the set of command tabs and ribbons that comprise the Table Tools The Design

command tab

and its Ribbon are displayed The Table1 tabbed document window in Design view

The Data Type

drop-down list arrow button

The Data Type

drop-down list

Select

(26)

6. An optional comment may be stored in the Description column. To do so, move to the Description column by pressing the Tab key or clicking in the Description text box. Type the text Surrogate key for CUSTOMER, then press the Tab key to move to the next row. The Table1 tabbed document window now appears as shown in Figure AW-1-28.

Figure AW-1-28 — The Completed CustomerID Column

7. The other columns of the CUSTOMER table are created using the sequence described in steps 3 through 5. See Figure AW-1-31 on page 29 for Description column data.

8. In order to set the number of characters in text columns, edit the Text Field Size text box as shown in Figure AW-1-29 on the next page. The default Field Size is 255, which is also the maximum value.

9. In order to set a column to required, click anywhere in the column Data Type Required property text box to display the Required property drop-down list arrow button, and then click the button to display the Required property drop-down list as shown in AW-1-30 on the next page.

10. Select Yes in the Required property drop-down list. The default is No (not required), and Yes must be selected to make the column required.3

The completed

CustomerID column

(27)

Figure AW-1-29 — Editing the Text Field Size

Figure AW-1-30 — Setting the Column Required Property Value

Edit this number to set the number of characters

Click anywhere in the Required text box to display the arrow the Required

property drop-down list arrow

(28)

Now we need to set a primary key for the CUSTOMER table. According to Figure AW-1-23, we will use the CustomerID column as the primary key for this table.

Setting the CUSTOMER Table Primary Key

1. Move the mouse cursor to the row selector column of the row containing the CustomerID properties as shown in Figure AW-1-31, and click to select the row.

Figure AW-1-31 — Selecting the CustomerID Row

2. Click the Primary Key button in the Tools group of the Design ribbon, as shown in Figure AW-1-32 on the next page. CustomerID is selected as the primary key for the

CUSTOMER table. The row

selector column—move

the mouse cursor into this column to select a specific row Move the mouse pointer here, then click to select the

(29)

Figure AW-1-32 — Setting the Primary Key

We have completed building the CUSTOMER table. Now we need to name the table, save it, and close the table.

Naming, Saving, and Closing the CUSTOMER Table

1. To name and save the CUSTOMER table, click the Save button in the Quick Access Toolbar. The Save As dialog box appears as shown in Figure AW-1-33.

Figure AW-1-33 — Naming and Saving the CUSTOMER Table

2. Type the table name CUSTOMER into the Save As dialog box text box, then click OK. The table is named and saved. The table name CUSTOMER now appears on the Click the Primary Key button in the Tools group of the Design ribbon to set CustomerID as

the primary key A key symbol is placed here to indicate that

CustomerID is

the primary key of the table

Click the Save

button in the

Quick Access Toolbar to display the Save

As dialog box

Type the table name

CUSTOMER in

the Table Name text box

(30)

Figure AW-1-34 — The Named CUSTOMER Table

3. To close the CUSTOMER table, click the Close button in the upper right corner of the tabbed documents pane. After the table is closed, the CUSTOMER table object remains displayed in the Navigation Pane as shown in Figure AW-1-35.

Figure AW-1-35 — The CUSTOMER Table Object

The table object

CUSTOMER is

displayed in the Navigation Pane The table is now named

CUSTOMER

the table name

CUSTOMER

now appears on the document tab Click the Close

button to close

the CUSTOMER table

The table object

CUSTOMER is

(31)

Inserting Data into Tables—The Datasheet View

There are three commonly used methods for adding data to a table. First, we can use the work with table as a datasheet, which is visually similar to and works like an Excel worksheet. When we do this, the table is in Datasheet view (the capital “D” in Datasheet is the correct spelling), and we enter the data cell by cell. Second, we can build a data entry form for the table, and then add data using the form. Third, we can use SQL to insert data. We will cover the first two of these in this section, and we will use SQL in a Section 3 of “The Access Workbench.”

In Access 2007, Datasheet view can also be used to create and modify table characteristics. When we open a table in Datasheet view, the Table Tools contextual includes a Datasheet command tab and ribbon with tools to do this. We do not recommend this, and prefer to use Design view as previously discussed in this section for creating and modifying table structures. Of course, before we can use either method we need some data to put into the table. Data for some of Wallingford Motors customers is shown in Figure AW-1-36.

Figure AW-1-36 — CUSTOMER Data

Adding Data to the CUSTOMER Table in Datasheet View

(32)

Figure AW-1-37 — The CUSTOMER Table in Datasheet View

NOTE: Just as in a worksheet, the intersection of a row and column in a datasheet is

called a cell.

2. Click the Shutter Bar Open/Close Button to collapse the Navigation Pane. This makes more of the CUSTOMER datasheet visible, as shown in Figure AW-1-38 on the next page. 3. Click the CUSTOMER document tab to select the CUSTOMER table in Datasheet view. 4. Click the cell in the CustomerID column with the phrase (new) in it to select that cell in

the new row of the CUSTOMER datasheet.

5. Press the Tab key to move to the LastName cell in the new row of the CUSTOMER datasheet. For customer Ben Griffey, type Griffey into the LastName cell. Note that as soon as you do this, the AutoNumber function puts the number 1 into the CustomerID cell, and a new row is added to the datasheet, as shown in Figure AW-1-39 on the next page.

6. Using the Tab key to move from one column to another in the CUSTOMER datasheet, enter the rest of the data values for Ben Griffey. When you enter the email address [email protected], the Access editor (just like in Microsoft Word) does not like the two capital letters at the start of the address and will change the second capital to lowercase—so be sure you edit these back to two capitals!

The Table Tools

contextual tab The Datasheet command tab If you need to switch between the Datasheet View and the Design View we used to create the table, use the

Design View

button

The Shutter Bar

Open/Close Button

The CUSTOMER tabbed document window with the table in

(33)

Figure AW-1-38 — The Collapsed Navigation Pane

Figure AW-1-39 — Entering Data Values for Ben Griffey

7. The final result is shown in Figure AW-1-40 on the next page. Note that column width of the Email column was expanded using the mouse to move the right-hand border of the column—just like you do in an Excel worksheet.

The CUSTOMER tabbed document window with the table in

Datasheet view The Shutter Bar

Open/Close Button

The collapsed

Navigation Pane

A new, blank row is added to the datasheet This row has been

(34)

Figure AW-1-40 — The Completed Row of Data Values

NOTE: If you make a mistake and need to return to a cell, click the cell to select it—you

will be in edit mode. Alternatively, you can use Shift to move to the right or Shift-Tab to move to the left in the datasheet, and then press F2 to edit the contents of the cell.

NOTE: Remember that LastName, FirstName, and Phone require a data value. You will

not be able to move to another row or close the table window until you have some value in each of these cells!

NOTE: Figure AW-1-40 shows a column labeled Add New Field to the right of the Email

column. This is one of the table tools in Datasheet view that can be used to create or modify table structures. We do not recommend using these tools—use table Design

view instead!

8. Use the Tab key to move to the next row of the CUSTOMER datasheet and enter the data for Jessica Christman as shown in Figure AW-1-36 above.

9. Adjust the datasheet column widths so that the contents of the datasheet can be seen in one screen. The final result is shown in Figure AW-1-41.

Column widths can be adjusted by using the mouse to drag the column border to the desired width The Access editor will change the second capital letter to lowercase—be sure to change it back! Many column widths had to be adjusted to get all the data to show in one window—Use the mouse to drag the column borders to the desired widths Click the Close

(35)

10. Click the Close button in the upper right corner of the document window to close the CUSTOMER datasheet. A dialog box will appear asking if you want to save the changes you made to the layout (column widths). Click the Yes button.

11. Click the Shutter Bar Open/Close Button to expand the Navigation Pane. This makes the objects in the Navigation Pane visible.

Modifying Data in Tables—The Datasheet View

Once data is entered into a table, you can modify or change it by editing the data values in the datasheet view. To illustrate this, we will temporarily change Jessica Christman’s phone number to 206-467-9876.

Modifying Data in the CUSTOMER Table in Datasheet View

1. In the Navigation Pane, double-click the CUSTOMER table object. The CUSTOMER table window appears in a tabbed document window in Datasheet view.

2. Click the Shutter Bar Open/Close Button to collapse the Navigation Pane. 3. Click the cell containing Jessica Christman’s phone number to select it. Access

automatically puts the cell into edit mode.

NOTE: If alternatively you use the Tab key (or Shift-Tab to move to the right in the

datasheet) to select the cell, press the F2 key to edit the contents of the cell.

4. Edit the phone number to 206-467-9876.

NOTE: Remember that Phone has a 12-character field size. You will have to delete

existing characters before you can enter new ones!

5. Press the Enter key, or otherwise move to another cell, to complete the edit. The CUSTOMER datasheet appears as shown in Figure AW-1-42.

Figure AW-1-42 — The Modified CUSTOMER Datasheet

(36)

6. Since we really don’t want to change Jessica’s phone number, edit the Phone value back to its original value of 206-467-3456. Complete the edit, then click the Save button in the Quick Access Toolbar to save the changes.

7. Click the Close button in the upper right corner of the document window to close the CUSTOMER datasheet.

8. Click the Shutter Bar Open/Close Button to expand the Navigation Pane.

Deleting Rows in Tables—The Datasheet View

Once data is entered into a table, you can delete the entire row in the datasheet view. To illustrate this, we will temporarily delete Jessica Christman’s data.

Deleting a Row in the CUSTOMER Table in Datasheet View

1. In the Navigation Pane, double-click the CUSTOMER table object. The CUSTOMER table window appears in a tabbed document window in Datasheet view.

2. Click the Shutter Bar Open/Close Button to collapse the Navigation Pane.

3. Right-click the row selector cell on the right side of the CUSTOMER datasheet for the row containing Jessica Christman’s data. This selects the entire row and displays a shortcut menu, as shown in Figure AW-1-43.

Figure AW-1-43 — Deleting a Row in the CUSTOMER Datasheet

NOTE: The terms row and record are synonymous in database usage.

4. Click the Delete Record command in the shortcut menu. As shown in Figure AW-1-44, on the next page an Access dialog box appears warning you that you are about to The Delete

Record

(37)

Figure AW-1-44 — The Access Deletion Warning Box

NOTE: As also shown in Figure AW-1-44, Access 2007 with default settings also performs

the visual trick of actually removing the row! However, the row is not permanently deleted until you click the Yes button in the Access dialog box. If you click the No button, the row will reappear.

5. Click the Yes button to complete the deletion of the row.

NOTE: Alternatively, you can also delete the row by clicking the row selector cell, then

pressing the Delete key. The same Access dialog box shown in Figure AW-1-44 will appear at this point.

6. Since we do not want to really lose Jessica’s data at this point, add a new row to the CUSTOMER datasheet containing Jessica’s data. As shown in Figure AW-1-45, the CustomerID number for Jessica is now 3 instead of 2. In an AutoNumbered column, each number is only used once!

Figure AW-1-45 — The New CustomerID Number

7. Click the Close button in the upper right corner of the document window to close the CUSTOMER datasheet.

8. Click the Shutter Bar Open/Close Button to expand the Navigation Pane. The row with

Jessica

Christman’s data has already been visually removed!

Click the Yes button to actually delete the row

(38)

Inserting Data into Tables—Using a Form

Now, let’s create and use an Access form to insert data into a table. Access has a form generator as part of its application generator functions. We could build a form manually in Form Design View, but we’ll take the easy route, and create an Access Form Wizard instead. Access 2007 provides us with a variety of tools for creating forms, and the Form Wizard is somewhat hidden in the More Forms gallery in the Forms group on the Create ribbon. Once started, the Form Wizard takes us through a step-by-step process to create the form we want.

Creating a Data Entry Form for the CUSTOMER Table

1. Click the Create command tab to display the Create Ribbon.

2. Click the More Forms gallery arrow button to display the More Forms gallery as shown in Figure AW-1-46.

Figure AW-1-46 — The More Forms Gallery

3. Click the Form Wizard button in the More Forms gallery shown in Figure AW-1-46. The Form Wizard appears as shown in Figure AW-1-47 on the next page.

4. The CUSTOMER table is already selected as the basis for the form, so we only have to select which columns we want on the form. We can choose columns one at a time by highlighting the column name and clicking the right-facing single chevron button. We can also choose all the columns at once by clicking the right-facing double chevron button. We will add all the columns, so click the right-facing double chevron button to add all of the columns, then click the Next > button.

NOTE: In a real-world situation, we may not want to display the CustomerID value. If so, The Create command tab The Form Wizard button The Create Ribbon

The More Forms

(39)

Figure AW-1-47 — The Form Wizard

6. We are now asked “What style would you like?” We will use the default Access 2007 style, so click the Next > button.

7. We are now asked “What title do you want for your form?” Type the form title WMCRM Customer Data Form in the text box, and then click the Finish button. As shown in Figure AW-1-48, the completed form appears in a tabbed document window and a WMCRM Customer Data Form object is added to the Navigation Pane.

The Form

Wizard

The CUSTOMER table is already selected Click the

right-facing single chevron button

Click the

right-facing double chevron button

to select all of the fields in the table The Next button

(40)

NOTE: The WMCRM Customer Data Form is properly constructed and sized for our

needs. Sometimes, however, we may need to make adjustments to the form design. We can make form design corrections by switching to Form Design view. To switch to Form Design view, we would use the Click the Design View button in the View Gallery.

Now that we have the form we need, let’s add some data to the CUSTOMER table using the form.

Inserting Data into the CUSTOMER Table Using a Form

1. Click the New Record button shown in Figure AW-1-48. A blank form appears. 2. Click the LastName text box to select it. Enter the data for Rob Christman shown in

Figure AW-1-36. You can either use the Tab key to move from text box to text box, or you can click on the text box you want to edit.

3. When you are done, use Steps 1 and 2 to enter the data for Judy Hayes. When you are done, your form will appear as shown in Figure AW-1-49.

Figure AW-1-49 — The WMCRM Customer Data Form for Customer Judy Hayes

4. Click the Close button in the upper right corner of the documents window to close the The WMCRM

Customer Data Form with the

data for Judy Hayes

The Close button

(41)

Modifying Data and Deleting Records—Using a Form

Just as we can modify data and delete rows in Datasheet View, we can edit data and delete records using a form. Editing data is simple—move to the record you want to edit by using the record navigation buttons (First Record, Previous Record, etc.) shown in Figure AW-1-49, click on the appropriate field text box, and then edit the contents. Deleting a record is also simple— move to the record you want to edit by using the record navigation buttons and then click the Delete Record button in the Delete drop-down list of the Records group of the Home Ribbon as shown in Figure AW-1-50. We will not use these capabilities at this time.

Figure AW-1-50 — The Delete Record Button

Creating Single Table Access Reports

One common function of an application is to generate printed reports. Access 2007 has a report generator as part of its application generator functions. Just as with forms, we could

(42)

Creating a Report for the CUSTOMER Table

1. Click the Create command tab to display the Create Ribbon as shown in Figure AW-1-51.

Figure AW-1-51 — The Report Wizard Button

2. Click the Report Wizard button shown in Figure AW-1-51. The Report Wizard appears as shown in Figure AW-1-52.

Figure AW-1-52 — The Report Wizard

3. The CUSTOMER table is already selected as the basis for the report, so we only have to select which columns we want on the form. Just as with the form wizard, we can choose columns one at a time by highlighting the column name and clicking the right-facing single chevron button. We can also choose all the columns at once by clicking the right-facing double chevron button. We will use only the following columns: LastName,

FirstName, Phone, Fax, and Email. Click each column name in the Available Fields list to

The Create command tab The Create Ribbon The Report Wizard button The Reports group The Report Wizard The CUSTOMER table is already selected

Click the

right-facing single chevron button to select the highlighted field in the table The Available Fields list

(43)

Figure AW-1-53 — The Completed Column Selection

NOTE: You can only select one column at a time. The usual technique of selecting more

than one column name at a time by pressing and holding the Ctrl key while clicking each additional column name does not work.

4. Click the Next > button.

5. We are now asked, “Do you want to add any grouping levels?” Grouping can be useful in more complex reports, but for a simple report listing the customers we don’t need any groupings. Instead, we’ll use the default ungrouped column listing, so click the

Next> button.

6. As shown in Figure AW-1-54 on the next page, we are now asked, “What sort order do you want for your records?”. The most useful sorting order is by last name, with sorting by first name within identical last names. For both sorts we will want an ascending sort (from A to Z). Click the sort field 1 drop-down list arrow and select LastName. Leave the sort order button on its current setting of Ascending.

7. Click the sort field 2 drop-down list arrow and select FirstName, leave the sort order button on its current setting of Ascending, and then click the Next> button.

8. We are now asked, “How would you like to lay out your report?” We will use the default setting of tabular layout, but click the Landscape orientation radio button to change the report orientation to landscape. Then click the Next> button.

9. Now we are asked, “What style would you like?” We will use the default setting of

Office. Then click the Next> button.

10. Finally, we are asked, “What title do you want for your report?” Edit the report title to read Wallingford Motors Customer Report. Leave the Preview the report radio button selected. Click the Finish button. As shown in Figure AW-1-55 on the next page, the completed report appears in a tabbed document window, a Reports section has been The Next button

The Selected

(44)

Figure AW-1-54 — Choosing the Sort Order

Figure AW-1-55 — The Finished Report

11. Click the Close button in the upper right corner of the documents window. The Next button

Select

LastName from

the drop-down list

The sort field 1

(45)

Closing a Database and Exiting Access 2007

That completes the work we’ll do in this section of “The Access Workbench.“ We have learned to create a database, to build database tables, forms and reports, and to populate a table with data using Datasheet view and a form. We will finish by closing the database and Access.

Closing the WMCRM Database and Exiting Access 2007

(46)

Access Workbench Exercises

AW.1.1 The Wedgewood Pacific Corporation (WPC) was founded in 1957 in Seattle, Washington, and has grown into an internationally recognized organization. The company is housed in two buildings. One building houses the Administration, Accounting, Finance, and Human Resources departments, while the second houses the Production, Marketing and Information Systems departments. The company database contains data about company employees, departments, company projects, company assets such as computer equipment, and other aspects of company operations.

A. Create an Access database named WPC.accdb.

B. Figure 1-28 shows the column characteristics for the WPC EMPLOYEE table. Using the column characteristics, create the EMPLOYEE table in the WPC.accdb database.

Figure 1-28 — Column Characteristics for the EMPLOYEE Table

(47)

Figure 1-29 — Wedgewood Pacific Corporation EMPLOYEE Data

D. Create a data input form for the EMPLOYEE table named WPC Employee

Data Form. Make any adjustments necessary to the form so that all data

displays properly. Use this form to enter the rest of the data in the EMPLOYEE table shown in Figure 1-29 into your EMPLOYEE table.

References

Related documents