tutorial 1 introduction to microsoft (ms) · pdf filetutorial 1 introduction to microsoft ......

11

Click here to load reader

Upload: trinhnhan

Post on 05-Feb-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1

INTRODUCTION TO MICROSOFT (MS) ACCESS

After reading this tutorial and completing the associated exercises, you will be able to:

• Open MS Access • Create tables using MS Access • Create forms and use them to enter data into tables

Note: Be sure to work through the examples in this tutorial as you read. This is the way you will learn by doing. LEARN MICROSOFT ACCESS: A RELATIONAL DATABASE APPLICATION Microsoft Access is a relational database application that is part of the Microsoft Office suite of applications. A database is an organized way to store data and database software, and usually provides features that allow a user to add, delete, update, and manipulate (transform) data. A relational database, like MS Access, stores data in tables. A table consists of rows (records) and columns (fields). Although the appearance of the records and the fields resembles the rows and columns you may have seen in a MS Excel worksheet, Access is a much more powerful tool than Excel for organizing, storing, and retrieving data. Much of this additional power comes from the relational model that is implemented by MS Access. If you have already used and studied Excel, you may recall that data tables list all data for a particular entity (customer, product, etc) in a row of the worksheet. So, if a customer makes 100 purchases, and a business tracks their address in a database, that address would be listed 100 times. The relational model used by MS Access allows us to store data in separate tables and then link tables via common fields—the primary key/foreign key relationship. A primary key is a field in a table that will contain a unique value for each and every record in the table. In other words, if a field is a primary key, you can’t use a specific value more than once in that column. A foreign key is a field in one table that contains values that are stored in a primary key in another table. If we look at the foreign key for a specific record, we can use the value to look up more data in the table where that field is used as a primary key. We are then guaranteed to find only one record that matches that value. Basically, a foreign key field provides a reference to a record in another table.

Page 2: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access ACC1-2

For example, we would relate tables via the CustomerID (the primary key) in one table, say, the Customer table and a copy of the CustomerID (a foreign key) in another table, say, the CustomerLoan table. The customer’s address is stored only once in the Customer table. This reduces data redundancy and improves updating and other database functions. Most of this tutorial will be spent learning by building. First you will create a database consisting of one table, and then you will create a form to enter data. In later tutorials, you will learn how to query this table for information and to create reports based on this information. You will also learn how to add tables to this data, then you will create the remaining tables, and finally you will link the tables by creating relationships and a query to a multi-table database. For this unit on MS Access, we will use a database example involving an Internet-based bank. We will start with a table that has information on the types of loans that the bank makes: home, auto, student, and so on. This information will include an ID number for each type of loan, the name of the loan type, the interest rate on this type of loan, and the minimum amount on this type of loan that the bank will extend. Later on we will add a table for the bank’s customers, and a table of the loans made to customers. LEARN AND BUILD: TABLES Step 1: Launch the MS Access Program You can open MS Access in several ways. The most general way is to click on the Start Button (lower left corner of screen), then choose Programs, then Microsoft Access (this may be one more level down; you may have to choose the Microsoft Office folder first). You may also have an MS Office choice at the top of the Start Menu. Step 2: Creating a new database When Access opens, you should see the screen shown in Figure 1. The Window on the right of the screen is called the Task Pane. You should click on “Create a new file...” and then “Blank Database” from the list that appears.

Page 3: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access

ACC1-3

Figure 1 – Access Screen when First Loaded

Step 3: Save the database file Choose a location to store the new database, and give it a name of BankDatabaseExample. Click “Create” and you’re on your way. Note: The file type associated with an Access database has the file extension .mdb.

Figure 2 – File New Database Dialog

Figure 3 shows the screen you should see now. This is the Database Window for your new database. Note: The name is shown at the top of the Database Window. Access indicates that the file will be compatible with Access 2000 (XP). Access 2003 file format is not compatible with earlier versions of Access.

Page 4: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access ACC1-4

Figure 3 – Access is ready to begin making a Database

Step 4: Create the table Highlight the “Create Table in Design View” and double-click on it, or, press the enter key. You should see the Design View of your new table. Each row under the Field Name heading can be used to create a field in your database. In Figure 4, we have entered the field name LoanID, and we are choosing the Data Type AutoNumber.

Figure 4 – Table Design View

Page 5: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access

ACC1-5

Step 5: Creating the table structure

1) Click in the first row under Field Name. 2) Type in the following Field Name: LoanID (no spaces). Usually, field names are

created by combining the name of the entity that corresponds to the table and a logical name for the attribute that will be stored in the field. Since this table will store data about a loan, all of our fields will start with the word “Loan.” We will then use a name for the particular field. Note that it is often acceptable to abbreviate the first part of the name. For example, CustID might be an acceptable name for the primary key in a Customer table. Also, it is customary to capitalize the first letter of each word in the field name. You will do this later in this tutorial when you create the fields LoanType, LoanRate, and LoanMin. The goal is to keep the names identifiable, understandable, and “non-mixup-able”.

3) Press the Tab Key or click in the Data Type Column to the right of where you just typed in LoanID. The field now says “Text.” You need to change this to AutoNumber.

The data type of a field determines what type of data can be stored in a field and the memory capacity used by the field in each record. If you scan the list, you will see several different data types. To get a listing and descriptions of the different data types, search Access Help using the keywords, “Access data types.” AutoNumber is a special data type provided by the Access software to use with primary keys. Access will automatically fill a field using the AutoNumber data type with the next unique value. Access makes sure that an AutoNumber field is unique by never assigning a value to the field again—even after a record is erased. The default Field Size for an AutoNumber field is Long Integer. The field size determines how much memory will be used to store numeric data in each field. For numbers, the amount of memory and format is set when you choose a numeric data type for the field type. You need to be aware of this. When a primary key is used as a foreign key in another table, you need to make sure that the foreign key uses a data type that is compatible with the data type of the primary key (Long Integer for AutoNumber).

► Thinking Critically Would you use the AutoNumber data type if the bank has its own loan identification system? Why or why not?

4) Press the Tab Key or click in the Description Column. Here you can type a

brief description of the data that will be stored in this field. Type in something appropriate about the field.

5) Create three additional fields as shown in Figure 5: LoanType with a data type of Text, LoanRate with a data type of Number, and LoanMin with a data type of Currency.

Page 6: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access ACC1-6

Figure 5 – Adding Fields to tblLoan

6) Because the LoanRate field created above is a decimal number, we need to change the Field Size from the default Long Integer to Double. The double field type is used whenever you will use numbers with a decimal portion. We also need to change the format for this field to Percent. The result of doing this is shown in Figure 6.

Figure 6 – Modifying the Format for the LoanRate Field

7) Now go back to the first Field Name (LoanID) and click on it. On the Table Design Toolbar (the toolbar with the small pictures (icons) on it), click on the

Key button ( ). You have just designated LoanID as the primary key for your table. You should now see a key icon to the left of the field name.

8) Now go back to the LoanType Field Name and click on it. Look down the screen to the Field Properties section of the Table Window. Notice that the Field Size for the LoanType field is set to 50. This means that you can enter up to 50

Page 7: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access

ACC1-7

characters in the field. A typical loan type is a “15-year conventional mortgage,” but even if you typed in “Special type of mortgage only available to Intro to IS students,” you’ve used less than 50 characters (Exactly how many? _____). You should determine the longest name for a type of loan that your bank offers and adjust the field size accordingly. In a small database, a few extra bytes here and there will not affect performance, but in a nationwide or international bank, with billions of records, every byte (character) counts.

9) Add appropriate descriptions for the remainder of the fields in this table. 10) You should also try out some of the other field properties such as Default Values

and Required (or not). Notice that when you select a field property a description of it will appear in the box on the bottom right of the window.

11) Click the Save button ( ) on the Table Design Toolbar. 12) The Save As dialog box pops up. Type tblLoan in the Name Text box, and then

press the enter key. Using “tbl” as a prefix is a good way to organize the database objects (tbl = table, frm = form, qry = query, rpt = report) that you create.

That’s it!! You’ve created a table in Access! Changing Views So far, you have used the Design View to create the tblLoan table. In addition to the Design View, there are three other views: the Datasheet View, the PivotTable View, and the PivotChart View. In this introductory tutorial on MS Access, we will only consider the Design and Datasheet views. Open the tblLoan table by double-clicking on it if it is not already open. You can switch between views of your table by selecting from a list available on the top left portion of the access screen.

Figure 7 – Possible Views of a Table

Now, click the datasheet view menu option to see the datasheet view of the table from which you can enter data directly. You could begin to enter data like that shown in the figure.

View button

Page 8: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access ACC1-8

Figure 8 – Datasheet View of Loan Table

If you are creating a database with more than one table, you should wait to enter data only after all tables and their relationships are created. We’ll add more tables to this example in the next tutorial. Just below the word “File” in the upper left corner of your screen, is the View button. Click it again and you are back to the Design View. Don’t enter data yet! We’ll use the form discussed in the next section to enter data. LEARN AND BUILD: FORMS You will now learn how to create a form using the Form Wizard provided by MS Access to use in data entry. Forms are used to provide a more formal and sometimes easier method of data entry than simply using the datasheet view of a table. They are also important when you want users to enter data, but you don’t want them to have access to the actual table. To enter data into the tblLoan table, you create the Loan form (frmLoan). To do this, within your Database Window, click on the Forms Object button (the third one down in the list of objects). You should see a screen like that shown in Figure 9.

Page 9: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access

ACC1-9

Figure 9 – Starting Form Wizard

Double-click on the “Create form by using wizard” selection. The Form Wizard should open as shown in Figure 10.

Figure 10 – Form Wizard

Your main goal in this window is to select the fields that you want to be in the input form. To do this, use the arrow buttons to move fields from the Available Fields list to the Selected Fields list.

Page 10: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access ACC1-10

The and arrows will move one selected field at a time, and the and arrows will move all fields in a list over to the other list. Follow the steps of the wizard, which will guide you through the creation of a form starting, selecting the double greater-than sign to include all fields in the form. Accept the default in all other steps of the creation process and save the form as frmLoan. The resulting input form is shown in Figure 11 with the data for the first loan type already input.

Figure 11 – Input Form

Now you are ready to enter data! Use the form shown in Figure 11 to input the data shown earlier in Figure 8. Caution: Enter the loan rate as a decimal value even though it is shown as a percentage (0.045 instead of 4.50). Note that as you enter the data, the LoanID field automatically changes since it is an AutoNumber field and creates a new, unique LoanID value. When you are through, simply close the form and display the tblLoan table, and it should look like Figure 8. BUILD: EXERCISES TO BUILD YOUR KNOWLEDGE OF MS ACCESS This assignment requires you to create the database table and form discussed above. You should do the following to complete this exercise:

1) Complete the design of the database table tblLoan as described above. Note: in this and in all future creations of tables, it is essential that you spell the field names exactly as they are show in the tutorial. Failure to spell them correctly will result in your database not working as planned!

2) Complete the design of the form frmLoan as described above. 3) Enter the data shown in Figure 8 into tblLoan using the frmLoan.

Page 11: Tutorial 1 INTRODUCTION TO MICROSOFT (MS) · PDF fileTutorial 1 INTRODUCTION TO MICROSOFT ... you may have to choose the Microsoft Office folder first). ... Introduction to Microsoft

Tutorial 1: Introduction to Microsoft (MS) Access

ACC1-11

ACCESS TUTORIAL 1 MINI-CASE Scenario: Nick, the owner of a small shop catering to the local fishermen, decided to expand his product line when the lake started to dry up due to a drought. Blessed with a large parking area, he decided to add car sales, and thus, his business was reborn as Nick’s Bait, Tackle, and Used Cars. Determined to keep his used car inventory as organized as his assortment of shiners and larvae, Nick decided that he needed to build a database. He’d start small with one table and then expand it as necessary. Nick realized that it’s generally better to create a design with all of the tables that would be needed first, but he figured that a one-table database would be sufficient for a while, and anyway, it would be a good way to learn how to use Microsoft Access. Your Task: Create an Access database with a table called tblVehicle to keep up with the list of cars on the lot of Nick’s store. Your database should conform to the following requirements:

1) Create your tblVehicle table to hold the following data for each vehicle. You’ll need to name your fields using the correct naming convention, and set the various parameters for the field to match the description of the field provided.

Field Description

ID Number A 6-digit identification chosen by Nick that may use both numbers and letters

Dealer Cost Price that Nick paid for the car; should be stored in the appropriate currency format

Blue Book Estimated used car sales price based on the industry standard “Blue Book” values; should be stored in the appropriate currency format

Type Type of vehicle; data values here can include car, truck, SUV, etc.

Sold A Yes/No field that can be checked as Yes for vehicles that have been sold/No for vehicles that have not been sold

2) Create a form for entering data into the tblVehicle table. 3) Use your form to enter the following data:

ID Cost Blue Book Type Sold

01086 $13,550 $17,888 Car Yes

01145 $10,500 $12,599 Truck No

01319 $8,100 $9,300 SUV No

A0554 $11,430 $12,800 Car Yes