|
Access |
|
You will need to save this file to your pc. Adventure Works 03.mdb Microsoft Access provides many ways to change the entry,
format, properties, organization, and storage of information in your
database tables. As the tables in your database become more efficient,
your database becomes more efficient. Format the font attributes for a table datasheet Your test database should be open. You will now open the tblEmployees table in datasheet view and change the appearance of the datasheet. You will change the font used for the table, the size of the font, and the font style. In the Database window, on the Objects bar, click Tables, if necessary. All tables currently defined in the database will be listed in the Database window. Click tblEmployees, and click Open on the Database window toolbar. The table opens in Datasheet view. Notice that the table appears in the default format of 10-point Arial font with silver gridlines. If the Formatting (Datasheet) toolbar is not visible, click the View menu, point to Toolbars, and click Formatting (Datasheet). The Formatting toolbar appears. On the Formatting toolbar, click the Font down arrow, scroll down, and then click Times New Roman. The font changes to Times New Roman. On the Formatting toolbar, click the Bold button. The font changes to bold. On the Formatting toolbar, click the Font Size down arrow, and click 12. The font changes to 12 points. You will now change the table background to light blue, use a special effect to make the cells appear raised, and then adjust the column widths to accommodate the formatting changes. On the Formatting toolbar, click the Fill/Back Color down arrow, and click a light blue square. The table background changes to light blue. On the Formatting toolbar, click the Special Effect down arrow, and click the Raised (second) option. The table changes to the raised cell effect. Next, you will change the column widths on some of the columns in order to view all of the data for those fields. Move the mouse pointer over the line between the Address and City field names until the pointer changes to a resizing doubleheaded arrow. When the pointer changes to the double-headed arrow, you can double-click it to automatically adjust the column width, or you can drag it left or right to change the width. Double-click the line. The column expands so that the widest record in the Address field, 241 W. 29th Avenue, is fully visible. Double-click the line between the City and State field names. The column expands so that the widest record in the City field, Sandyland Cove, is fully visible. Scroll to the right, and double-click the line between the Home Phone and Notes field names. The column expands so that all the phone numbers are fully visible. Save the tblEmployees table to save your changes. Every field in an Access table has a set of field properties that can be set and adjusted to make sure your data looks like you expect it to look. The properties available for any given field depend on the Data Type defined for the field. You can modify these properties in Design view by first selecting the field, then accessing the property you want to change in the lower half of the Design view window. In Access, the data entered into fields and the appearance of that data are controlled by field properties. You set and adjust field properties in the Field Properties section of the Table Design view window. Every field has field properties specific to the data type for the field. However, a few field properties are common to almost all data types: The Field Size property limits the number of characters contained in text fields and the amount of disk space reserved for number fields. For example, if you have a field that contains state abbreviations (such as NY or CA), you could limit the size of the field to only two characters to reduce the chance for errors. Text fields can be set to hold from one to 255 characters. Number fields have several advanced settings, which are beyond the scope of this course. ■ The Format property allows you to specify a format for the data in the field. For example, if the field will contain a date, you can choose from several date and time formats such as Short Date (10/27/05) or Long Date (Wednesday, October 27, 2005). ■ The Caption property sets a caption for a field, which will appear as the field name—instead of the field name—when the table is in Datasheet view. For example, a field name might be EmployeeID (without spaces), but if the caption is Employee ID (with a space), Employee ID (with a space) will appear on the datasheet. ■ The Default Value property reduces the time spent on data entry by automatically entering a default value in a field every time a new record is added to the table. This is a good feature to use if the data in a certain field is almost always the same. For example, if most of Adventure Works guests are from California, you could enter CA as the default value for the State field in a table containing guest addresses. If a guest comes from out of state, you can delete the default value and enter the correct state. You have seen that you can change the overall appearance of the datasheet. You can also modify the appearance of individual fields by modifying field properties. You will now add captions to some of the fields, change the date format of the DateHired field, and use the Field Size property to limit the size of the EmployeeID field. You will also specify a default value for the Hours field. Click tblHumanResourcesData, and click Open on the Database window toolbar. The table opens in Datasheet view. Note that the field names appear without spaces in them, dates appear in Short Date format (such as 2/25/98), and the first blank record already has a default value of 0 entered in the Hours field. On the Table Datasheet toolbar, click the View button. The table appears in Design view, with the Employee ID cell already selected. The properties for the EmployeeID field appear in the Field Properties section of the Table Design view window. In the Field Properties section, click in the Caption box, and type Employee ID (with a space). The caption of the EmployeeID field changes to Employee ID. In the Field Properties section, click in the Field Size box, delete the existing text, and then type 4. All employee identification numbers at Adventure Works are four characters long. Access will now limit the Field Size for the EmployeeID field to four characters. In the Field Name column, click in the DateHired cell. The properties for the DateHired field appear in the Field Properties section of the Table Design view window. In the Field Properties section, click in the Format box, click the down arrow that appears, and then click Medium Date. The format of the DateHired field changes to Medium Date. The Medium Date format displays dates as 25-Feb-98. Click in the Caption box, and type Date Hired (with a space). The caption of the DateHired field changes to Date Hired In the Field Name column, click in the Hours cell. The properties for the Hours field appear in the Field Properties section of the Table Design view window. In the Field Properties section, click in the Default Value box, delete the existing text, and then type 40. The default value for the Hours field changes to 40. This value will now appear in the blank record at the end of the current datasheet data. On the Table Design toolbar, click the Save button. An alert box appears, warning that some data might be lost because you changed the Field Size property for one of the fields. Click Yes. Access saves the table with the changes you have made. On the Table Design toolbar, click the View button. The table appears in Datasheet view. Note that the EmployeeID field has the caption Employee ID (with a space), the DateHired field has the caption Date Hired (with a space), the data in the DateHired field follows the Medium Date format, and the Hours field in the blank record at the bottom of the table displays a default value of 40. Even if you didn’t follow a particular order when you first entered data into a table, you can quickly organize the data in a field alphabetically or numerically by performing a sort. There are two types of sorts: ascending and descending. An ascending sort organizes the data in a field from the lowest value to the highest or in alphabetical order starting with A. A descending sort has the opposite effect; it organizes the data in a field from the highest value to the lowest or in reverse alphabetical order starting with Z. The tblHumanResourcesData table is open in Datasheet view, and you have modified some of the field properties in a previous exercise. You would like to see the data in descending salary order, so you will sort that field using the Sort Descending button. You then perform another sort so that the employee IDs appear in order, from lowest to highest. Click in any record in the Salary field, and click the Sort Descending button on the Table Datasheet toolbar. Access reorganizes the table in descending order by salary. The record for the employee who earns the largest salary of $45,200 appears at the top. Click in any record in the EmployeeID field, and click the Sort Ascending button on the Table Datasheet toolbar. Access reorganizes the table in ascending order by employee ID. The record for employee H101, whose employee ID number is first in ascending order, appears at the top. Save the tblHumanResourcesData table. Tables in Access often get very large, and finding certain data can become very time-consuming. To locate specific information in a table, you can use the Find command. For example, in a table listing employee names and addresses, you could use Find to locate the record for an employee with a specific last name or to locate all addresses for employees who live in Santa Barbara. You can use the Find command to search just one field or the entire table. If you are working with a large table, limiting your search to a single field means that the search will run faster than it would if the search had to examine all the information in the table. For example, if you are searching for the employee with the last name of Chai, the search will run faster if you search just the LastName field, instead of the entire table. By default, Access searches the last field you clicked in before beginning the search. If you want to search the entire table, you can select that option in the Find and Replace dialog box. The tblHumanResourcesData table is still open in Datasheet view, sorted on the EmployeeID field. You will now use the Access Find command to search the table for any employees with a job title of Host. Click in any cell in the Title field. On the Table Datasheet toolbar, click the Find button. The Find and Replace dialog box appears, with Title already in the Look In box. In the Find What box, type Host, and click Find Next. Access selects the record that contains Host in the Title field Close the Find and Replace dialog box. By using a filter, you can restrict data so that only records in a table meeting certain criteria are displayed. For example, you can create a filter to view records in tblHumanResourcesData for only employees who earn more than $30,000 a year. In Access, you can create filters in two different ways. Filter By Form allows you to specify a field and a specific value in that field to use as the filter. Filter By Selection filters based on the contents of the currently selected field. Filters do not affect the table itself, and they can be turned on and off using the Apply Filter and Remove Filter buttons. These two buttons are actually the same button; the button name changes (although the picture on the button does not) depending on the filter state. After you have created a filter, the Apply Filter button becomes the Remove Filter button. When you click the Remove Filter button, the table reverts to its original display. Applying and remove Access filters You previously used the Find command to locate specific data. You can also use the Access Filter commands to find data. You will first use the Filter By Form feature to create a filter that restricts the data in tblHumanResourcesData to employees who work 40 hours each week. You will then use the Filter By Selection feature to create a filter to find only those employees who have the job title of Marketing Rep. On the Table Datasheet toolbar, click the Filter By Form button. The Filter By Form window for tblHumanResourcesData appears. Click in the Hours field, click the down arrow that appears, and then click 40. On the Filter/Sort toolbar, click the Apply Filter button. The table appears, showing only records for employees who work 40 hours each week. On the Table Datasheet toolbar, click the Remove Filter button. The table returns to its original display. In the Title field, click in any record containing Marketing Rep. On the Table Datasheet toolbar, click the Filter By Selection button. The table appears, showing only records for employees with the title Marketing Rep. On the Table Datasheet toolbar, click the Remove Filter button. The table returns to its original display. Save the tblHumanResourcesData table. Close the tblHumanResourcesData table You can establish relationships between tables that
contain similar information or fields. There are three types of
relationships that you can establish between the fields in tables:
one-to-one, one-to-many, and many-to-many. Many-to-many relationships are
beyond the scope of this lesson. The field that is used to establish a
relationship between two tables is referred to as the join field. A
one-to-one
relationship exists when two tables have an identical field
containing the same information, meaning each record in a table has one
matching record in a related table. For example, both tblEmployees and
tblHumanResourcesData have an EmployeeID field that contains 28 records
listing the employee IDs for the same 28 employees of Adventure Works. The
lists are identical, which means that employee H101 has one record in
tblEmployees (listing the employee’s address and phone number) and one
record in tblHumanResourcesData (listing the employee’s salary, position,
date of hire, and hours worked per week). The relationship between
tblEmployees and tblHumanResourcesData is a one-to-one relationship
because if there is a record containing H101 in the EmployeeID field of
tblEmployees, there is one and only one record containing H101 in
tblHumanResourcesData |