IT tutorials
 
Office
 

Microsoft Access 2010 : Maintain Data Integrity (part 6) - Restricting Data to Values in Other Tables

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Product Key Free : Microsoft Office 2019 – Serial Number
4/27/2013 9:23:13 PM

6. Restricting Data to Values in Other Tables

You learned how to link tables in such a way that a user could not enter a customer ID that did not exist in the Customers table or an employee ID that did not exist in the Employees table. These relationships are critical to ensuring that any specific item of data is stored in the database only once. But relationships also provide a powerful means to improve the accuracy of the database’s data.

If you ask a dozen sales clerks to enter the name of a specific customer, product, and shipper in an invoice, it is unlikely that all of them will type the same thing. In cases like this, in which the number of correct choices is limited (to actual customer, actual product, and actual shipper), providing the means to choose the correct information from a list derived from the Customers table, the Products table, and the Shippers table will improve your database’s accuracy and consistency.

One of the key concerns when looking up information in another table is the efficiency of the process. Looking up an employee in an Employees table with nine records is not very difficult. Looking up a customer in a Customers table with 200 records, however, could be quite tedious. If you use an intuitive CustomerID instead of relying on an autogenerated number as the primary key of the Customers table, database users can type the CustomerID and then verify it in the list. For example, using the first three letters of a customer’s last name plus the first two of his or her first name will almost certainly result in unique CustomerID values. These values will not only serve as the primary key for the Customers table but will be easy for users to intuit when working in other tables linked to the Customers table.

In this exercise, you’ll use the Lookup wizard to create a list of possible values for a field from the entries in a field in a related table. You’ll also change the primary key in a table to facilitate the lookup process.

Set Up

You need the GardenCompany06 database you worked with in the preceding exercise to complete this exercise. Open the GardenCompany06 database, and then follow the steps.

  1. On the Database Tools tab, in the Relationships group, click the Relationships button.

    image with no caption

    The Relationships page shows that in this database, there is a relationship between the Customers and Orders tables and between the Employees and Orders tables. You want to create Customer and Employee lookup fields in the Orders table, so you first need to delete the existing relationships.

  2. Right-click the diagonal part of the line between the Customers and Orders tables, and click Delete, clicking Yes to confirm the deletion. Repeat this step for the line between the Employees and Orders tables. Then close the Relationships page, clicking Yes to save the change.

    Tip

    If you want to remove a table’s box from the Relationships page, you can right-click the box and click Hide Table. If you want to remove all the boxes, you can click the Clear Layout button in the Tools group on the Design contextual tab.

  3. Open the Orders table, and drag across the CustomerID and EmployeeID field names to select those fields. On the Fields contextual tab, in the Add & Delete group, click the Delete button. Then click Yes to permanently delete the fields and Yes to delete their indexes.

    image with no caption

    Now we’ll add a new Employee lookup field.

  4. At the right end of the table, click the Click to Add field. On the Fields contextual tab, in the Add & Delete group, click the More Fields button, and then click Lookup & Relationship.

    image with no caption

    The Lookup wizard starts and displays its first page.

  5. With I want the lookup field to get the values from another table or query selected, click Next.

    The Lookup wizard asks you to identify the table on which the lookup field will be based.

  6. Click Table: Employees in the list, and click Next.

  7. On the next page, in the Available Fields list, double-click EmployeeID, then FirstName, and then LastName to transfer those fields to the Selected Fields list. Then click Next.

  8. On the next page, click the arrow for the first sort box, click LastName in the list, and then click Next.

    The wizard displays the lookup list with the EmployeeID field (the key column) hidden.

    Tip

    You can adjust the column widths to fit the values.

  9. Click Next. On the wizard’s last page, type Employee as the name of the field, and select the Enable Data Integrity check box. Then click Finish.

  10. Click in the Employee field of the first record, and then click the arrow at the right end of the field.

    The list of possible entries for this field appears.

    Tip

    The list is in alphabetical order by last name.

  11. Click Nancy Anderson to enter the name Nancy as the salesperson for this order.

    Now let’s work with the Customers table. First we want to change the primary key for this table.

  12. Open the Customers table in Design view. On the Design contextual tab, in the Tools group, click the Primary Key button to turn it off. Then change the Data Type setting for the CustomerID field to Text.

    image with no caption
  13. Change the Field Size property to 5, and enter an Input Mask property of >LLLLL;;.

    This input mask will force Access to display the CustomerID in capital (uppercase) letters, no matter how it is entered.

  14. Click the CustomerID field in the Field Name column, and in the Tools group, click the Primary Key button. Then save the table.

  15. Switch to Datasheet view. For each customer, assign a CustomerID that consists of the first three letters of the last name and the first two letters of the first name.

    Even if you type the ID in all lowercase letters, Access displays them in uppercase.

  16. Sort the table in ascending order on the CustomerID field, and then close it, clicking Yes to save your changes.

  17. In the Orders table, use the Lookup wizard to create a new lookup field based on the CustomerID, FirstName, and LastName fields of the Customers table. Sort the lookup list on LastName, and then click Next.

  18. On the page that asks you to adjust the width of the columns in the lookup field, point to the right border of the FirstName field name, and when the pointer changes to a double-headed arrow, drag all the way to the left to hide that column. Click Next.

  19. Name the field Customer, and enforce referential integrity. Then click Finish.

    Now try entering an order for Pilar Ackerman.

  20. In the Customer field of the first record, type ack.

    Ackerman is the only LastName value beginning with those letters, so Access completes the entry for you.

  21. Click the field in the record below.

    Access enters the name Ackerman as it appears in the Customers table.

  22. In the active record, type c.

    Access enters campbell, the first LastName value beginning with c in the Customers table. This is not the customer we want.

  23. Click the arrow at the right end of the field.

    Access displays the list with Campbell highlighted.

    Tip

    Because Access has scrolled the list, it is easy to select the name you want.

  24. Click Cox, and press Tab. Then close the Orders table.

  25. On the Database Tools tab, in the Relationships group, click the Relationships button.

    The Lookup wizard automatically created one-to-many relationships between the Customers and Orders tables and between the Employees and Orders tables.

    Tip

    Access created these relationships to support the lookup fields in the Orders table.

Clean Up

Close the GardenCompany06 database.

Multivalued Fields

Usually you will be able to build database tables in which each field holds only one value. However, sometimes you might need to store more than one value in a single field. For example, in a Projects table, you might need to store multiple employee names in a Team field.

To set up a multivalued field that restricts values to those in a table:

  1. Create a new lookup field, and indicate on the first page of the Lookup wizard that you want to look up the values in a table.

  2. On the second page, select a table from the list.

  3. On the third page, select the fields you want to include.

  4. On the fourth page, indicate any sorting.

  5. On the fifth page, make any necessary adjustments to the column width.

  6. On the last page of the wizard, type a name for the field, indicate whether to enforce referential integrity, and select the Allow Multiple Values check box.

When the table is open in Datasheet view, clicking the field’s arrow displays a list from which users can choose entries by selecting their check boxes. Clicking OK then displays the selected values in the field.

 
Others
 
- Microsoft Access 2010 : Maintain Data Integrity (part 5) - Restricting Data to Values in Lists
- Microsoft Access 2010 : Maintain Data Integrity (part 4) - Restricting Data by Using Validation Rules
- Microsoft Access 2010 : Maintain Data Integrity (part 3) - Restricting the Format of Data
- Microsoft Access 2010 : Maintain Data Integrity (part 2) - Restricting the Amount of Data
- Microsoft Access 2010 : Maintain Data Integrity (part 1) - Restricting the Type of Data
- Microsoft Project and the Project Management Domain : Using Microsoft Project with Methodologies and Life Cycles
- Microsoft Project and the Project Management Domain : Exploring Project Management Industry Standards
- Microsoft OneNote 2010 : Formatting Text (part 2) - Inserting Symbols and Special Characters, Copying and Applying Formatting with the Format Painter
- Microsoft OneNote 2010 : Formatting Text (part 1) - Setting the Default Font, Changing Basic Text Formatting, Using the Styles Gallery
- Microsoft Visio 2010 : Managing and Styling Pages (part 3) - Controlling Page Size and Orientation, Setting Page Scales
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us