60
UNIVERSITY INFORMATION TECHNOLOGY TRAINING & DOCUMENTATION DEPARTMENT DOING MORE WITH ACCESS 2007: DATA ENTRY AND PROTECTION

De Access 07

Embed Size (px)

Citation preview

Page 1: De Access 07

UNIVERSITY INFORMATION TECHNOLOGY

TRAINING & DOCUMENTATION DEPARTMENT

DOING MORE WITH ACCESS

2007: DATA ENTRY AND

PROTECTION

Page 2: De Access 07

University Information Technology Training & Documentation Department 2

Page 3: De Access 07

University Information Technology Training & Documentation Department 3

Table of Contents

Introductory Notes ............................................................................................. 4 Setting Up Your Data ........................................................................................ 5 Creating a Database ......................................................................................... 5

Templates ...................................................................................................... 5

Creating Tables ................................................................................................. 9

Input Mask ................................................................................................... 14 Validation Rule ............................................................................................. 22 Lookup ......................................................................................................... 26 Using the Lookup Wizard ............................................................................. 28 Default Value ............................................................................................... 32

Referential Integrity ...................................................................................... 36

Creating Forms ............................................................................................... 43

Creating a Form Using Autoform ................................................................. 43

Adjusting Form Fields .................................................................................. 46 Removing and Adding Form Fields .............................................................. 49

Changing the Overall Format of a Form ...................................................... 57 Creating A Trusted Location ........................................................................ 58

Page 4: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 4

INTRODUCTORY NOTES “Doing More With Access: Data Entry and Protection” assumes that you have completed “Getting Started with Access,” offered by our Training Department. Therefore, basic terminology and navigation will not be addressed in this course. Rather, this course picks up where “Getting Started” left off, focusing on advanced data manipulation and reports. “Doing More with Access: Data Entry and Protection” will give you, the Access user, more options for protecting data and streamlining data entry. In today's class, we will set up data entry rules, define input masks, and look at referential integrity. We will create and enhance forms and build controls such as combo boxes and check boxes. Throughout today’s session, the following topics will be covered:

Creating a Database

Creating a Table

Use of various data types

Adjusting field properties

Using an Input Mask

Setting Validation Rules

Creating a Lookup

Setting Referential Integrity

Creating a form

Formatting and customizing a form

Page 5: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 5

SETTING UP YOUR DATA In this section of the class, you will learn how to:

Create a database

Create tables

Use various data types

Adjust field properties

Use an Input Mask

Set Validation Rules

Create a Lookup

Set Referential Integrity

In today's class we will build a small database. We will create a database, create tables from scratch, link the tables, and look at their relationships. We will look at data entry protection and create rules and guidelines for protecting the data. We'll finish by creating a form and polishing the appearance of our database.

CREATING A DATABASE You have a number of options available when you wish to create or build a database. The first option is to copy an existing database by copying and pasting it (and then change the content). If a co-worker or friend has a database that they have created, you could copy their design and enter your information into the database. This option is a time and work saver.

TEMPLATES Secondly, you can open Access and look at the options available in the form of Templates. Template categories such as Featured, Local, and Office Online are listed in the left side of the window. Templates are pre-built databases, such as an assets or contacts database, which come with a selection of tables, forms, and reports with fields to match the database category. The benefit of using a

Page 6: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 6

2template is that the database objects such as tables and reports are already premade. The Featured listings are generally the most popular. Local templates (11 of them by default) are stored on your computer, while the Online versions are freely available from Microsoft. You then enter your data into the existing structure. The New Blank Database option is still available, while recently opened databases are listed on the right-hand side of the window. To open Access:

1. Select Start > All Programs > Microsoft Office > Microsoft Office Access 2007. When you open Access 2007, you are presented with this Getting Started window:

To download a template from Microsoft Office online:

2. With the Getting Started Page open, click a Featured Online Template such as Assets. The file name appears in the right side of the window. If you do not have an internet connection, in the left-hand Template Categories, select Local Templates and select a local template such as Assets.

Page 7: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 7

3. In the right side of the window, notice the new file extension for Access

files, .accdb.

Older Access files such as Access 2000 and Access 2002-2003 can be opened in Access 2007. The file will probably default to downloading into your Documents folder. If you

prefer, you can select another destination by clicking the Browse folder .

4. On the right side of the window, click Download . The 2007 template downloads and opens, with the Access Help window open.

5. Minimize the Help window.

The Title bar at the top of the window reflects the Access 2007 file format

If you had opened an older version of an Access database, the Title bar would have reflected that format as well:

Page 8: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 8

The template comes with ready-to-use tables, forms, queries, and reports and is ready to accept data or to be modified to meet your design considerations. (The Assets template comes with 21 objects: 3 tables, 2 queries, 8 forms, and 8 reports.)

6. Close the Assets database.

7. Reopen Access. The Getting Started window opens.

8. Click Blank Database. In the right side of the window, the Filename Database 1 displays.

9. Name the database "training."

10. Click Create. The new database is created and opens without any tables, queries, or forms.

Page 9: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 9

CREATING TABLES We will begin by creating three tables: a Customers table, a Products table, and a Transactions table. The tables are the foundation of the database. Tables should contain data that is related (these concepts were covered in the Getting Started class). To create a new table:

1. On the Ribbon, on the Create tab, in the Tables group, click the Table tool. The new table opens in Datasheet View.

2. On the Ribbon, click the View tool. The Save As window opens.

3. Name the table tblCustomers. Table names are usually plural, while field names are generally singular.

4. Click OK. The table displays in Design View.

Page 10: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 10

We will create 5 fields in the Customer table. The fields, or attributes, in this table will hold information related to customers. Access has auto-entered an “ID” field name in the first open cell in the Field Name field.

5. Just begin typing to replace the ID field name with CustID.

Field names should be descriptive and unique. Try to use a field name only once in your database (why we are replacing ID with CustID). Don't get too wordy with your field names; stay away from acronyms and try to use the singular form of the name. Many people also do not include spaces in field names. Note: For further Access naming conventions, review the Leszynski/Reddick Guidelines for Access.

6. Press Tab or Enter. The cursor displays in the Data Type field. The Data Type field consists of eleven choices that determine the kind of value that can be stored in the field (these were covered in the Getting Started class). The choices that are made here begin the process of defining the parameters for data entry. We will cover a number of these in class today. We will choose "Text" for the data type, which allows us to use both numbers and letters.

7. In the Data Type field, select Text as the Data Type.

The lower half of the screen is the Field Properties area. The Field Properties area is where you control and define the data that will be entered into the table.

Page 11: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 11

Based on the field you have selected, such as Text, its properties, or settings display in the Field Properties area. In our scenario, our Customer IDs are never more than 8 characters (our company doesn't use more than 8 characters). We will change the Field Size property from the default 225, which is the limit for Text, to 8 characters. This will prohibit anyone from entering a string of characters more than 8 in length. Access can also process a smaller field size faster.

8. In the Field Properties area, in the Field Size field, change the 225 to 8.

9. Click back up in the last field, Description (the 3rd column).

The Description field is just that: a place to add any detail or notations regarding the field. If someone else has to maintain or inherit your database, notations here will help a co-user or the next user to understand your logic. The Description will also show up in the Status Bar when entering data into that field.

10. Type "Unique customer ID number."

Your screen should look like this:

11. Press Tab. The cursor moves down to the next open Field Name field. You can now enter the second Field Name.

12. In the Field name column, below CustID, type LastName.

Page 12: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 12

13. Press Tab. The cursor moves to the Data Type field. Leave the data type as Text, the default. In the Field Properties area (lower half of the screen), notice that the field for Required is set to No. At this point, if an individual is entering a record into the tblCustomers table, she/he can leave this field empty, it is not required. We do not want this field left empty. We want the field to contain a value or last name.

14. In the Field Properties, in the Required field, double-click No. The "No" toggles to "Yes."

Because there are only two choices (Yes or No), double-clicking is a shortcut method.

15. Back at the top of the window, in the Field name column, in the open 3rd Field Name cell, type FirstName.

16. Press Tab. The cursor moves to the Data Type field.

Page 13: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 13

Here is another shortcut method for selecting the Data Type:

Click the down-arrow in the Data Type field.

There are eleven data type choices. If you know that you want "Currency," type "C" and Currency will be chosen. If you want "Number," type "N." By typing the first letter of any of the eleven data types you want, that data type will be selected. Leave the Data Type set to Text.

17. Tab over and down to the next open row.

18. For the 4th Field Name, type CustPhone.

19. Tab to the Data Type field.

Page 14: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 14

INPUT MASK An Input Mask is a tool that makes data entry easier and controls what values an individual can enter into a table. Use of an input mask results in consistent entries into a field. We will use the Input Mask Wizard and then we will manually define criteria for another Input Mask.

1. Check to make sure that your cursor is in the CustPhone field.

2. In the Field Properties area, click in the Input Mask field. A button appears with 3 dots, the build button.

3. Click the Build button. Save your work, and then the first step of the wizard opens.

The first window in the Wizard prompts you to choose a mask.

4. Scroll through the various choices.

5. Select Phone Number.

6. Click in the Try It area to try the input mask. Notice the placeholders.

Page 15: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 15

7. Click Next. The placeholder step opens. You are prompted regarding changing the input mask or changing the type of placeholder we wish to have displayed. A placeholder is a character that appears in the field "holding the place," waiting for you to enter data. Once you enter data, the placeholder is replaced and disappears. In this instance, the default, the underscore ( _ ) is the cleanest looking character.

8. Click in the Try It area to test the mask.

If you would like to see how the other characters display, try them.

9. Click Next. The how do you want to store the data step opens. This screen gives you a choice of how you would like the data stored in the table, with or without symbols (symbols or literal characters). Symbols do take up space in the database. On the other hand, the data is easy to read with symbols.

10. Choose "Without the symbols…"

11. Click Next. Access is ready to create the mask.

Page 16: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 16

12. Click Finish. The Input Mask is created.

The Input Mask code that displays is in three sections, separated by semicolons. The first section is the mask itself. The second section specifies whether or not the symbols will be stored: 0=yes, empty space=no (in our case, it is an empty space). The third section is the character that Access displays as a placeholder. We will add one more field to the table for customer State so that we can create another Input Mask.

13. In the next available Field Name cell, type CustState.

14. Press Tab. The cursor moves to the Data Type field.

15. In the Properties area, click in the Input Mask field. Here is a partial listing of characters that can be used in creating an input mask from scratch, taken from the MS Access help:

We will create an input mask from scratch, by simply typing in the appropriate characters.

Page 17: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 17

Looking at the listing of characters on the preceding page in the left hand column, what three characters would you type into the Input Mask field so that only two letter characters would be allowed in the field which would convert them to uppercase, entry required (i.e. only entries such as MA or ma or Ma would be allowable) ?

16. Type in those three characters.

Your screen should look like this:

Observe that the CustID field is the primary key as it is the unique identifier in this table. Access had created the table with the initial ID field designated as the Primary Key, which we overwrote.

17. Click the View tool. You are prompted to Save the table.

18. Click Yes. The table displays in Datasheet View. The tblCustomers table, with five customer fields, is ready for accepting data.

Page 18: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 18

Before you enter data into the new Customers table, notice the Status bar at the base of the window.

"Unique customer ID number" is displayed. This is displayed because you entered it into the Description field in Design View. To enter data and test the data entry properties:

1. In the CustID field, try to type nine or more 1's.

Once you reach eight characters, you are prevented from entering any more because you limited the field size to eight characters.

2. Adjust the CustID to read 111.

3. Press Tab. The cursor moves to the LastName field.

4. Leave the Last Name field blank and press Tab again. The cursor

moves to the FirstName field.

Although this is set as a data entry required field, Access won't stop you from entering other data into other fields until you try to leave this record.

5. In the FirstName field, type David.

6. Press Tab. The cursor moves to the CustPhone field.

7. To see the Input Mask in action, type the digit 6. The Input Mask is revealed.

8. Type in any phone number.

One of the limitations of the input mask is that the data must fit the form exactly. For instance, if you have an international phone number, it cannot be entered

Page 19: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 19

into this field. If you find that there are exceptions to your mask that keep cropping up, you may want to remove the mask entirely.

9. Press Tab. The cursor moves to the CustState field.

10. Type a lower case m and a lower case a. The input mask is adjusting the data.

11. Try adding another character. The input mask prevents any additional

characters.

12. Press Enter.

Access is warning you that the LastName field cannot be left empty, it must contain a value. In the Field Properties, you had earlier set the Required field to Yes.

13. Click OK. The warning window closes.

14. Click in the LastName field and type Bragg.

15. Tab down to the next record. The data is now accepted and saved. To enter a second record.

16. In the CustID field type 222.

17. Press Tab. The cursor moves to the LastName field.

18. In the LastName field, type Murphy.

19. Press Tab. The cursor moves to the FirstName field.

Page 20: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 20

20. In the FirstName field, type Collin.

21. Press Tab. The cursor moves to the CustPhone field.

22. In the CustPhone field, type any phone number.

23. Press Tab. The cursor moves to the CustState field.

24. In the CustState field type MA.

25. Press Tab. The cursor moves to the next record.

We will only use two records today in this table.

26. Close out of the tblCustomers table. We will create two more tables in this database. The next table will contain products.

1. On the Ribbon, on the Create tab, in the Tables group, click the Table tool. The new table opens in Datasheet View.

2. On the Ribbon, click the View tool. The Save As window opens.

Page 21: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 21

3. Name the table tblProducts.

4. Click OK. The table displays in Design View.

5. In the first Field Name cell, replace ID by typing ProdID.

6. Press Tab. The cursor displays in the Data Type field.

7. In the Data Type field, select Text as the Data Type.

8. Press Tab. The cursor displays in the Description field.

9. In the Description field, type Unique product ID number.

10. Press Tab or Enter. The cursor moves down to the next open Field Name field.

11. In the next Field Name cell, type ProdName.

12. Press Tab. The cursor displays in the Data Type field.

13. Accept the default Text for the Data Type.

14. Press Tab. The cursor displays in the Description field.

15. Press Tab again. The cursor moves down to the next open Field Name

field.

16. Type the third and last Field Name ProdPrice.

17. Press Tab. The cursor displays in the Data Type field.

Page 22: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 22

VALIDATION RULE In the tblCustomers table, the field size was controlled using the field properties. Access provides other methods to control the input of data. In this exercise, you will set a Validation Rule to control data input. A validation rule will provide boundaries to whoever is entering data into the table. The goal is to have "clean" data in your tables.

1. Make sure that the cursor is still resting in the ProdPrice field.

2. At the base of the window, in the Field Properties area, click in the Validation Rule field.

3. Type "between .01 and 100." Or type <=100

4. Press Enter. The cursor moves to the next field and the expression in the Validation Rule field is adjusted by Access

You have just set the parameters for data entry. Only values between one cent and one hundred dollars can be entered in the ProdPrice field. You could stop here, and if someone entered data out of the specified range, they would get a warning like you saw when we left the LastName field empty in the tblCustomers table. But you are going to write the text (the Validation Text) the user will see when they try to enter out-of-range data. In other words, you are going to customize the error message text.

Page 23: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 23

5. Make sure that the cursor is still resting in the Validation Text field in the Field Properties area.

6. Press Shift F2. The Zoom box opens to give you more room to work.

7. Type "The price must be between $0.01 and $100.00 in the ProdPrice

field." You have just rewritten the error message.

8. Click OK. The Zoom box closes.

9. Press Enter. The cursor moves to the next field. Again, there is no override for this rule. If you end up with products above the $100 range, either rewrite or eliminate the Validation Rule. The ProdID field is the primary key and should be unique. There should only be one occurrence (one row) of the ProdID in this table. There can be multiple occurrences of one ProdID in another table (when the primary key from one table appears in another table, that is called a Foreign Key, and these will appear in the next table we build). To save your work:

10. Press Ctrl + S.

11. Close the tblProducts table. The next step is to add products to the tblProducts table and test the validation rule.

1. Open the tblProducts table.

2. In the ProdID field, type 1.

3. Press Tab. The cursor moves to the ProdName field.

Page 24: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 24

4. Type wisdom in the ProdName field.

5. Press Tab. The cursor moves to the ProdPrice field.

6. In the ProdPrice field, type 5 (this is a value that is within the allowable range).

7. Press Tab or Enter. The cursor moves down to the next open Field

Name field. To create the next record:

8. In the ProdID field, type 2.

9. Press Tab. The cursor moves to the ProdName field.

10. In the ProdName field, type insight.

11. Press Tab. The cursor moves to the ProdPrice field.

12. In the ProdPrice field, type 500 (this is a value that is not within the allowable range).

13. Press Tab or Enter. An Access warning appears.

The validation rule is in effect and if protecting the data that is to be entered into the table. Notice the validation text you typed. The validation rule will not let the user out of the cell they are working in.

14. Click OK. The Access warning closes.

15. In the ProdPrice field, change the 500 to 50.

16. Press Tab or Enter. Access now allows the data entry and the cursor moves down to the next open Field Name field.

To create the last record:

17. In the ProdID field, type 3.

Page 25: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 25

18. Press Tab. The cursor moves to the ProdName field.

19. In the ProdName field, type imagination.

20. Press Tab. The cursor moves to the ProdPrice field.

21. In the ProdPrice field, type 100.

22. Press Tab or Enter. The cursor moves down to the next open Field Name field.

23. Close the Products table.

Lastly, we will build the third and final table, tblTransactions.

1. On the Ribbon, on the Create tab, in the Tables group, click the Table tool. The new table opens in Datasheet View.

2. On the Ribbon, click the View tool. The Save As window opens.

3. Name the table tblTransactions.

4. In the first Field Name cell, replace the ID filed by typing TransNum.

5. Press Tab. The cursor displays in the Data Type field.

Page 26: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 26

6. In the Data Type field, keep the default AutoNumber. AutoNumber is "A unique sequential (incremented by 1) number or random number assigned by Microsoft Access whenever a new record is added to a table." At the base of the window, in the Field Properties pane, if you click in the "New Values" field, you will see the two AutoNumber choices (Increment and Random).

7. Press Tab to move to the Description field.

8. Press Tab again, to move to the next Field Name cell. This table will be used to document all of the transactions. This table will also serve another database function. You will now bring in a field from each of the two previous tables that you have built. This will enable us to link the three tables so that data can be shared between tables. In the next Field Name cell you will enter “CustID.” This is the primary key field from the tblCustomers table.

9. Type CustID.

10. Press Tab. The cursor displays in the Data Type field.

LOOKUP While surfing the web, you have probably used a site, such as an airline, where you were required to type data into fields. Some of those fields, such as the State field, may have had a down-arrow as part of the field. When you clicked the down-arrow, a list appeared. This is an example of a lookup. A lookup is a data entry timesaver, an input mechanism to streamline data entry, and a data input watchdog. A lookup (a text box, combo box, or list box) provides limited choices to the individual who is entering data into a table or a form. A lookup prevents misspellings and data entry errors.

Page 27: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 27

1. Make sure that the cursor is still resting in the CustID field. In the lower half of the screen, in the Field Properties pane:

2. Click the Lookup tab. The Display Control field displays.

3. Click in the Display Control field. A down-arrow appears.

4. Click the Display Control down-arrow. A menu appears.

5. Select Combo Box. A number of other fields are now visible.

6. Click in the Row Source field. A down-arrow and build button appear.

7. Click the Row Source down-arrow (not the build button). The possible sources of the control’s data (in our case tables) display. The control we are using is a combo box.

8. Select tblCustomers. This is the table where the CustID field is located.

This is the table (that we created earlier) where the data will be pulled for the lookup.

Page 28: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 28

9. Click back up in the next Field Name cell below CustID.

10. Type ProdID. This is the field from the Products table.

11. Press Tab. The cursor displays in the Data Type field. In the Properties pane, on the Lookup tab:

12. Click in the Display Control field. A down-arrow appears.

13. Click the Display Control down-arrow. A menu appears.

14. Select List Box. A number of other fields are now visible. The difference between a list box and a combo box won't be apparent in your table. The difference will be apparent on a form. In a form, a list appears at all times, where a combo box is more compact and doesn't display until you open it (by clicking the down-arrow). You won't be able to view these differences in a table, but we will see the differences in a form in the next section of the manual. List boxes do not allow you the option of typing in another choice, although combo boxes do. Note that there is a help topic called, "Learn about the types of list box controls"

15. In the Field Properties pane, click in the Row Source field. A down-arrow and build button appear.

16. Click the Row Source down arrow (not the build button). The possible

sources of the control’s data (in our case tables) display. The control we are using is a list box.

17. Select tblProducts. This is the table where the ProdID field is located.

USING THE LOOKUP WIZARD You have another option that allows you to create a lookup field based on values that you input manually. For example, you may not have a table that holds the data that you wish to enter into a table, such as campus location. We will create a campus field, and then enter three campus options. If your database is properly designed, you may not have much of a call for this option.

1. In the next available Field Name cell, type Campus.

2. Press Tab. The cursor displays in the Data Type field.

Page 29: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 29

3. In the Data Type field, click the down-arrow and select Lookup Wizard… The Lookup Wizard opens.

4. Select I will type in the values that I want.

5. Click Next. The next step of the wizard opens.

Page 30: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 30

We only need one column, so we will leave the default at 1 column. To enter the 3 campus names:

6. Click in the first column and type Medford.

7. Press Tab. The cursor moves to the next row.

8. Type Boston and then press Tab. The cursor moves to the next row.

9. Type Grafton. You may also adjust the column width so that as little or as much of the option choice names, Medford, Boston, and Grafton, display.

10. Click Next. The last step of the wizard opens. The wizard has picked up the Campus label for the lookup column.

11. Accept the defaults and click Finish. The lookup column is completed. Before taking a look at the table in Datasheet view:

Page 31: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 31

Optionally:

12. In the Field Properties area, click the Lookup tab. The Field Properties display.

In the future, if you need to adjust the fields you are looking up or add or remove fields, you can edit the Row Source field. The fields/choices are included in quotes and separated by semicolons

13. Click Save.

14. Click back up in the next available Field Name cell.

15. Type TransDate.

16. Press Tab. The cursor displays in the Data Type field.

17. On the keyboard, press D. The Date/Time data type is selected.

Date/Time will accept values from 100 through 9999.

Page 32: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 32

DEFAULT VALUE When you are entering data into a new record, generally the field is blank or empty when it first appears in your table. Another data entry timesaver is to use a default value in the field. A default value is a value that appears in a new record field instead of an empty field. We will now set a default value that will reflect today's date. When the table is opened, the new record value will reflect today's date instead of the user having to type it in. The default value date can be adjusted.

1. Make sure that the cursor is still resting in the Date field. In the lower half of the screen, in the Field Properties pane:

2. On the General tab, click in the Default Value field.

3. Type =date()

Your screen should look like this:

Note: Excel users may notice that this is the same function that returns today's date in an Excel spreadsheet cell.

4. Click back up in the sixth Field Name cell.

5. For the final Field Name, type Posted.

6. Press Tab. The cursor displays in the Data Type field.

Page 33: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 33

7. On the keyboard, type y. The Yes/No Data Type is selected. Yes and No values and any fields that contain only one of two values (Yes/No, True/False, or On/Off) can be used here.

8. Press Tab. The cursor displays in the Description field. In the Description field:

9. Type Is the transaction posted?

10. Check to make sure that TransNum is the primary key field.

11. Close the table. You are prompted to save your work.

12. Choose Yes to save changes. The table closes. We will open the Transactions table and enter data.

1. Open the tblTransactions table. The 6 fields display.

Some characteristics of the table field properties are immediately noticeable:

The TransNum field reflects the AutoNumber attribute (a number that Access assigns to each record, either sequential or random).

The Date field has defaulted to today's date, for data entry ease, although it can be changed.

The Posted field has a checkbox, which is a graphical reflection of the yes/no field.

2. Press Tab. The cursor rests in the CustID field.

Page 34: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 34

Notice the down-arrow in the CustID field. This is how a combo box displays.

3. Click the down-arrow and select 111. There are only two customers to choose from in the tblCustomers table, which are the only two valid entries.

4. Press Tab. The cursor moves to the ProdID field. Notice the down-arrow in the ProdID field. This is a list box. Although there is no apparent difference in the datasheet between a list and a combo box, the difference will become apparent when we look at a form.

5. Click the down-arrow and select 2. There are only three products to choose from in the tblProducts table, which are the only valid choices.

6. Press Tab. The Campus field is now active.

7. Click the down-arrow and select Medford. These are the three choices

we created using the Lookup Wizard.

8. Press Tab. The Date field is now active.

9. To accept today's date, press Tab. In the final field “Posted," a check in the box represents Yes (posted), no check in the box stands for No (unposted). You can click with your mouse or use the space bar to add or remove a check.

10. Press the spacebar. A checkmark is entered in the field.

11. Press Tab or Enter. The record is completed.

Page 35: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 35

To enter a second record:

12. Press Tab or Enter again.

13. In CustID field, click the down-arrow and choose 222.

14. Press Tab. The cursor moves to the ProdPrice field.

15. Type 4.

16. Press Tab. The cursor moves to the Campus field. What do you notice? Access has allowed you to enter invalid data! This issue will be addressed in a moment.

17. Return to the ProdPrice field and change the 4 to 3, which is valid data.

18. Tab over to the Campus field.

19. Select any campus.

20. Tab over to the Date field.

21. Change the date to yesterday.

22. Tab over to the Posted field.

23. Leave this record unposted.

24. Press Tab. The second record is saved.

25. Close the tblTransactions table.

Page 36: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 36

REFERENTIAL INTEGRITY The data in our three tables is more likely to be accurate if we set the relationships between the three tables in our database. To establish a relationship, there must be a common field between the tables that you wish to link. In relationships, there will be a primary table, and a related table. In our training database, the tblCustomers and tblProducts tables are primary tables. The tblTransactions table is the related table. The linked field in the primary table is a primary key. That same field appears in the related table and is called a foreign key. The common field in the two related tables does not have to have the same name, but the Data Type must match (i.e. Text and Text or Yes/No and Yes/No). Referential integrity is a "system of rules that MS Access uses to ensure that relationships between records in related tables are valid, and that you don't accidentally delete or change related data." If you establish referential integrity, a value can't be added to a related table (tblTransactions) if it doesn't already exist in the primary table (tblCustomers or tblProducts). You are basically forcing the data to make sense! The three most common types of relationships are:

A one-to-many relationship:

A one-to-many relationship is the most common type of relationship. In a one-to-many relationship, a record in the tblCustomers table can have many matching records in the tblTransactions table, but a record in the tblTransactions table has only one matching record in the tblCustomers table.

A many-to-many relationship:

In a many-to-many relationship, a record in Table A can have many matching records in Table B, and a record in Table B can have many matching records in Table A.

Page 37: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 37

A one-to-one relationship:

In a one-to-one relationship, each record in Table A can have only one matching record in Table B, and each record in Table B can have only one matching record in Table A. This type of relationship is not common, because most information related in this way would be in one table. You might use a one-to-one relationship to divide a table with many fields, to isolate part of a table for security reasons, or to store information that applies only to a subset of the main table. For example, you might want to create a smaller table from a main employees table to track employees home address information. We will now define the table relationships and set referential integrity.

1. On the Ribbon, click the Database Tools tab. The functional groups display.

2. In the Show/Hide group, click the Relationships tool. The Relationships

window opens with the Show Table window.

In the Show Table window, the three tables are visible on the Tables tab.

3. With the tblCustomers table selected, click the Add button. The tblCustomers table is added to the Relationships window.

Page 38: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 38

4. Click to select the tblProducts table.

5. Click the Add button. The tblProducts table is added to the Relationships window

6. Follow the same procedure to add the tblTransactions table.

7. Close the Show Table window. The three tables display.

The three tables are unrelated as no relationships have been set yet. The graphic below shows the existing default relationships in the Northwind sample database. Note that all of the relationships are one-to-many.

We are ready to create the relationships and set the referential integrity. To create or define the relationship, you drag a field in the primary table to a corresponding field in the related table that contains the same data type. Notice that the primary key in each table has a small gold key icon in front of it.

Page 39: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 39

8. In the primary tblCustomers table, drag the CustID field to the CustID field in the related tblTransactions table. When you let go of the mouse, the Edit Relationships window appears.

In the lower part of the window, Access has defined the Relationship Type as "One-To-Many." There will only be one instance of the CustID in the tblCustomers table, but there may be many occurrences of the CustID field in the tblTransactions table.

9. Select the checkbox "Enforce Referential Integrity." The Cascade… choices become available. When selected, Cascade Update will update all records in related tables that are linked to the primary table when changes are made in the primary table. Cascade Delete will delete all related records in the related tables when the primary record is deleted.

10. Click Create. The relationship is created and the join line with the corresponding one-to-many symbols is added.

11. Optionally, in the Relationships window, try moving or dragging the tables around. The join remains.

The next step is to link the tblProducts table to the tblTransactions table.

12. In the tblProducts table, drag the primary ProdID field to the related ProdID field in the tblTransactions table. Upon mouse-up, the Edit Relationships window appears.

Page 40: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 40

13. Select the checkbox "Enforce Referential Integrity." This is another one-to-many relationship.

14. Click Create. The relationship is created and the join line with the corresponding one-to-many symbols is added.

Your screen should display these relationships:

15. Close the Relationships window. You are prompted to save the changes to the layout.

16. To save the changes, click Yes.

You are now ready to test the referential integrity among the tables.

1. Open the tblTransactions table.

2. Tab over to the CustID field of a new record.

3. Type 333 (although no customer 333 exists).

4. Press Tab. At this point, because the record hasn’t been saved, Access allows you to enter the bad data.

Page 41: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 41

5. In the ProdID field, type 5 (although no product 5 exists).

6. Press Tab. The cursor moves to the Campus field.

7. Pick a campus and press Tab. The cursor moves to the Date field.

8. Accept the default in the Date field and press Tab. The cursor moves to the Posted field.

9. Accept the default in the Posted field.

10. Press Tab again to attempt to save the record by moving to the next row.

A warning displays.

The 333 entry in the CustID field has violated referential integrity because there is no such related record in the tblCustomers table.

11. Click OK. The warning closes.

12. Change the incorrect 333 to 222.

13. Again, press the down arrow key to attempt to save the record by moving to the next record. A warning displays.

The 5 entry in the ProdID field has violated referential integrity because there is no such related record in the tblProducts table.

14. Click OK. The warning closes.

15. Change the incorrect 5 to 3.

Page 42: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 42

16. Press the down arrow key to move to the next record. This time referential integrity has not been violated and the record can be saved.

17. Close the tblTransactions table.

When referential integrity is enforced:

You cannot delete a record from a primary table if matching records exist in a related table. For example, if there are existing orders for product 2 in the tblTransactions table, you cannot delete product 2 from the tblProducts table. But, if Cascade Delete Related Fields has been checked, deleting records in the primary table will delete all related records in the related tables.

You cannot change a primary key value in the primary table if that record has related records in another table. For example, if there are existing orders for product 2 in the tblTransactions table, you cannot change the value for product 2 in the tblProducts table.

But, if Cascade Update Related Fields has been checked, updating records in the primary table will update all related records in the related tables.

Page 43: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 43

CREATING FORMS Filling out forms! Do you remember returning the fixture you bought to Home Depot? You waited in line, and when you arrived at the register, the clerk asked you, "Have you filled out the return form?" Of course you forgot the form! Once paper forms are filled out, someone has to enter the data (or it could be scanned) into a computer or database. Electronic forms have generally replaced paper forms. Once you enter or select data on a form, it can then be entered into a database. Microsoft Access allows you to create and modify forms. You are then able to add, select, or modify data with regard to your database. Do know that forms are not a necessity for manipulating or managing data as you can work directly with your tables in the database. Forms provide ease of access, protection of data, and provide a professional look or appearance.

CREATING A FORM USING AUTOFORM We could create a form from scratch just as we have created tables. Instead, we are going to use a timesaver called an Autoform. The Autoform uses an existing table or query to build a form that reflects the fields and attributes already present on the table or query. The user does not have to build or put in all the different fields one by one. To create a form from the tblTransactions table:

1. In the Navigation pane, check to make sure that the tblTransactions table is highlighted or selected.

2. On the ribbon, click the Create tab.

Page 44: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 44

3. In the Forms group, click the Form tool. A new form is created in Layout View based on the tblTransactions table.

4. On the ribbon, click the View tool down-arrow and select Form View.

The form displays all fields and records from the underlying table or query, which in our case is the Transactions table. The form takes the name of the table. All the records from the Transactions table are present (3). We have our checkbox and our date default. Notice the difference between the Combo Box in the CustID field (where the choices are hidden) and the List Box in the ProdID field. The form data reflects live data, so be careful not to change any information as you move through the records unless you intend to. Using a form for data entry helps to insure accuracy. Only one record is visible on the form and there is little chance of hitting a wrong key and overtyping a previously entered field in another record. All of the editing and entering rules still apply. The only difference is how you are viewing the data. Within the form window, the easiest way to navigate among the fields and make changes is with the use of the mouse. Use the mouse to click in any desired field, and enter the necessary changes to the data. If you prefer to use the keyboard, you can move from field to field in a forward direction with the [Tab] key and in reverse by pressing [Shift + Tab].

Page 45: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 45

We will begin by saving the form.

1. Click Save. The Save As window opens.

2. Name the form frmTransactions.

3. Click OK. We will proceed to make the form more attractive and user friendly.

4. On the Home tab of the ribbon, click the View tool down–arrow and select Design View. The form displays in Design View.

The form consists of a Form Header area at the top, which currently holds the form title, the Detail area where the data is housed, and the Form Footer area at the base of the form, which is currently empty.

Page 46: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 46

The physical area of the three form sections, Header, Detail, and Footer, can all be adjusted. To adjust or resize the form area:

1. Place the cursor on the bottom of the Form Footer bar. A two-headed vertical arrow appears.

2. Drag the cursor down to about the ½” mark on the vertical ruler. The Form Footer area is opened up.

We will add footer information in a moment.

ADJUSTING FORM FIELDS Once a form is created, elements and fields can be adjusted, added, or removed from the form. We will begin by adjusting and formatting the existing fields. The following adjustments can be accomplished in either Layout or Design View. One of the benefits of Layout View is that the form displays live data while you are making layout adjustment. The fields do not need to span the whole width of the form. To adjust the width or height of the fields:

Page 47: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 47

1. In Design or Layout View, click to select any of the fields. The field is highlighted in yellow.

2. Place the cursor on the far right edge of any of the fields. A two-headed horizontal arrow displays.

Make sure that the cursor is not a two-headed horizontal arrow with a

black vertical line in the middle.

3. Drag the cursor to the left. The fields are resized. To resize the height of field:

4. In Design or Layout View, click to select any of the fields. The field is highlighted in orange.

5. Place the cursor on the top or bottom edge of any of the fields. A

two-headed vertical arrow displays.

6. Drag the cursor up or down. The field is resized.

Page 48: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 48

You may have noticed that when the horizontal adjustments were made to one field, all of the fields responded. By default, Access places the fields or controls in a group or guide called a layout. The layout helps to align fields horizontally and vertically to give the form a uniform appearance. If you wish to separate the fields so that they can be manipulated individually:

1. On the ribbon, in Design or Layout View, click the Arrange tab.

2. Click any of the fields. The field is highlighted in orange and the layout selector at the upper-left corner of the layout displays

3. In the upper-left corner of the layout display, click the layout selector. All of the fields are highlighted.

4. In the Control Layout Group, click the Remove tool. The fields or controls are removed from the layout and can be adjusted independently.

Page 49: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 49

Design considerations:

In Layout View, if you click a field or its field label, the control will move without its partner.

To move both the control and its label, hold down the Shift key and select both of them.

In Design View, they will move together by default.

If you are in Design View and only want to move one of the pair, click the brown selection box in the upper left corner of the control.

5. Using the 4 headed arrow cursor, in either Design or Layout View, try rearranging any of the form fields.

REMOVING AND ADDING FORM FIELDS Once a form is built, you may want to remove a superfluous or unneeded field from the form. You may also want to add a different field or control of your choosing to the form. We will now remove a field from the form and then add a field and a control to the form. To remove a field:

1. In Design or Layout View, click the Posted field checkbox.

Page 50: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 50

2. On the keyboard, press Delete. The field and its label are removed from the form.

If you click just the field label, only the field label will be deleted. The field will remain.

Although the Posted field has been removed from the form, it still remains in the corresponding tblTransactions table. To add a field:

1. From Design View, on the Design tab, in the far right Tools group, click the Add Existing Fields tool. The Field List displays on the right side of the window.

or

2. From Layout View, on the Format tab, in the Controls group, click the

Add Existing Fields tool. The Field List displays on the right side of the window.

The Field List holds the fields from the table or query that the form is based on. In our case, we have the field list from the tblTransactions table.

3. Drag the field onto the form. The field is added.

Page 51: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 51

If you need to, separate a field from its label for formatting purposes, in the Control Layout Group, click the Remove tool as we did earlier.

If you are working in Design View, you may also need to open up or increase the Detail area by dragging the top of the Form Footer bar down.

The process you just completed is called adding a control. Controls are found on both forms and reports. Controls are used to perform certain actions, display data, or simply add artistic elements to the form or report. The two types of controls are:

Bound: a control on a form or report that is attached to a field in a record.

Unbound: a control on a form or report that is not attached to a field in a record.

All of the fields or controls on this form are bound to records in the tblTransactions table. The Posted field we just added is a bound control. Here is a tip for lining up fields and field labels:

1. Click once on the field or field label you wish to position. The field will be outlined in orange.

2. On the keyboard, use the arrow keys to position the field.

Page 52: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 52

The next step is to add an unbound control to the form, a footer that displays both the file name and path.

1. Make sure the form is in Design View.

2. Make sure that there is room in the Form Footer area for a field.

3. On the Form Design Tools Design tab, in the Controls group, click the

Text Box tool. The cursor changes shape .

4. Click in the Form Footer area. An Unbound field and field label appears.

5. Click in the Unbound field. The cursor sits in the field in editing mode.

6. Type the following expression in the field: =[CurrentProject].[FullName]

You may need to increase the width of the field.

Page 53: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 53

7. Click the field label and press Delete on the keyboard. The label is deleted.

8. View the form in Form View.

9. If needed, return to Design or Layout View and resize the field to accommodate the file name and path.

Other file name or path footer options:

file name with the complete path:

=[CurrentProject].[FullName]

file name without the file extension:

=Left([CurrentProject].[Name],Len([CurrentProject].[Name])-6)

just the path:

=CurrentProject.Path To remove the file name and path border:

10. Return to Design or Layout View.

11. Make sure that the Property Sheet is visible on the far right side of the window. (If not visible, on the Design tab, click the Property Sheet tool.)

12. Click the file name and path field.

13. On the right side of the window, in the Property Sheet, on the Format tab,

click the Border Style field down-arrow. The formatting choices display.

14. Select Transparent.

Page 54: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 54

15. View the form in Form View.

16. Save your work. To edit the form name in the Form Header area:

1. Return to Design or Layout View.

2. In the Form Header area, click the tblTransactions form label. The field is highlighted in orange.

3. Click the tblTransactions form label again. It is now in editing mode.

4. Edit the label to read “Transactions Input Form.”

Page 55: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 55

If you wish to make additional formatting changes to the label, such as font adjustments, use the tools on the Format tab. Adding Calculated Controls Calculated controls are a special type of unbound control whose contents are based on calculations. The expression used to perform the calculation is generally based on one or more fields of the underlying table or query. As an example, a table of Products might contain a Price field and a Quantity field. A calculated field called Total Cost would multiply the contents of the two fields, with an expression like =[Price] * [Quantity]. When creating a calculated control, you have to follow several guidelines:

All Calculated controls start with the equal sign =.

When referring to fields from the table, you must begin and end with a bracket [ ].

You can enter numbers for the calculation, if needed.

When calculating text fields, you use the “&” symbol to join them.

We will add a ship date to the form that is 10 days after the current date.

1. Make sure the form is in Design View.

2. Make sure that there is room in the form for the field.

3. On the Form Design Tools Design tab, in the Controls group, click the

Text Box tool. The cursor changes shape .

Page 56: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 56

4. Click in the Form area. An Unbound field and field label appears.

5. Click in the Unbound field. The cursor sits in the field in editing mode.

6. Type the following expression in the field: =Date() + 10

7. Select the field label default text and replace it by typing Ship Date.

8. View the form in Form View.

9. Save your work. Some other examples of calculations entered in controls are:

=[FirstName] & “ “ & [LastName] Takes the first and last name fields and joins them together, separated by a space.

=[Price] * [Quantity] Determines total amount by multiplying a price times the quantity ordered.

=([BirthDate]-Date())/365 Calculates the age (in years) from a birth date field.

Page 57: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 57

CHANGING THE OVERALL FORMAT OF A FORM

One of the simplest ways to drastically change the overall look of a form is to change the format using the AutoFormat selection.

Access 2007 includes 25 professionally-designed formats along with a Wizard to help create your own. The AutoFormat option is located on the Format tab. To apply a different form layout:

1. Before making these changes, save your work.

2. Return to Layout View. The form displays in Layout view.

3. On the ribbon, on the Format tab, in the far right AutoFormat group, click

the AutoFormat More arrow . A gallery of formatting choices displays.

4. In the gallery, select a desired AutoFormat option. The formatting is applied to the entire form.

Page 58: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 58

CREATING A TRUSTED LOCATION The Access Trust Center security feature is a tool used to prevent your computer from being hacked or infected by a virus. Viruses or hacker tools use code that may contain macros, the same kind of code that an Access action query such as a delete query uses. By blocking this code by default, Access is standing guard over your computer. A trusted location is a designated folder, usually on your computer, where you can place Access databases so that macros are not disabled by default. Placing a database in a trusted location (folder) saves you the step of having to enable the “mistrusted” content every time you open your database.

Default Security Warning that appears on the Message Bar every time you open an Access database that does not reside in a trusted location:

Creating a trusted location (folder) is a two step process: the first step is to create a folder and the second step is to designate it as a trusted location. To create a trusted location (folder):

1. Create a folder that will house your Access databases. For example, in the Documents folder, create a folder called “Databases.” It is not recommended to make your entire Documents folder a trusted location.

2. Click the Office Button. The menu displays.

3. At the base of the menu, click Access Options . The Access Options window opens.

4. On the left-hand column, click Trust Center. The Trust Center options

display.

5. Click Trust Center Settings . More Trust Center options display.

6. In the left Navigation area, click Trusted Locations.

Page 59: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 59

7. At the base of the window, click Add new location . The Microsoft Office Trusted Location window opens.

8. Click Browse . The Browse window opens.

9. Browse or navigate to the folder.

10. Click OK.

11. Click OK again. The folder is added to the trusted locations.

12. Click OK. The Trust Center window closes.

13. Click OK again.

14. Place your Access database in that trusted file. The next time you open it, the macros will not be disabled.

Page 60: De Access 07

Doing More with Access 2007: Data Entry and Protection

University Information Technology Training & Documentation Department 60

Tip

All databases created with Access 2007 come with default tab-based floating windows. If you open older databases created in previous versions of Access, such as 2000 or 2003, document tabs are automatically turned off. To turn on the tabs:

1. Click the Office Button . The menu displays.

2. At the base of the menu, click Access Options. The Access Options window displays.

3. Click Current Database. The options for the current database display.

4. In the Application Options section, under Document Window Options, click the Tabbed Documents choice.

5. Click OK. You must close and then reopen the database for the tabs to appear.