[ Team LiB ] |
Working with Data in a FormAfter you have opened a form, you probably want to work with the data you have bound it to. You most likely want to move from record to record, edit data, add new records, delete records, and copy records. The process of editing data includes learning important techniques such as how to select records, delete field contents, undo changes, and search and replace. The following sections cover all these techniques. Moving from Record to Record in a FormThe Navigation Bar appears at the bottom of the Form window (see Figure 4.4). It allows you to move from record to record. The First Record navigation tool moves you to the first record, the Previous Record navigation tool moves you to the previous record, and the Record Number navigation tool allows you to quickly move to a desired record. To the right of the Record Number tool are the Next Record tool, the Last Record tool, and the New Record tool. Figure 4.4. The Navigation Bar.You can also you use keystrokes to move from record to record. Pressing Page Down moves you forward through the records, one record at a time. Pressing Page Up moves you backward through the records, one record at a time. Pressing Ctrl+End moves you to the last record, and pressing Ctrl+Home moves you to the first record. Finally, Ctrl+ moves you to a new record. Editing the Data Underlying a FormYou can modify the table data from within a form. For example, you might want to change a customer's company name or address. Here's the process:
Deleting Field Contents Within a FormNow that you know how to modify the contents of a field, let's talk about how to delete the contents of a field. In following along with this section, make sure that you understand that you are not deleting records, you are simply deleting the contents of an individual field within a record. You would do this, for example, if you entered a region for a company and then realized that the company was located in a country that did not have regions. The process is simple: Undoing Changes Made Within a FormThere are many times when you need to undo changes that you made to a control or to a record. An example is when you started making changes to the incorrect control—or even to the incorrect record. Undo comes to the rescue! You have several different options for how to do this, depending on whether you are still within a control, have left the control, or have left the record. You can use the Undo feature only to undo the last change made to a control or changes made to the most recently modified record. Undoing Changes Made to the Current ControlWhen you are in the process of making changes to a control, you might realize that you really didn't want to make changes to that control or to that record. To undo changes to the current control, you can either click the Undo tool on the toolbar, select Edit | Undo Typing, or press the Esc key once. Undoing Changes After You Move to Another ControlThe process of undoing changes after you move to another control is slightly different from the process of undoing changes made to the current control. You can either click the Undo tool on the toolbar, select Edit | Undo Current Field/Record, or press the Esc key once. Undoing Changes After You Save the RecordWhen you make changes to a control and then move to another record, Access saves all changes to the modified record. As long as you do not begin making changes to another record, you can still undo the changes you made to the most recently modified record. To do this, you can either click the Undo tool on the toolbar, select Edit | Undo Saved Record, or press the Esc key twice.
Using a Form to Add New Records to a TableAccess adds records to the end of a table, regardless of how you add them to the table. To use a form to add new records to a table, follow these steps:
Using a Form to Delete Records from a TableBefore you can delete records, you must first select them. I therefore cover the process of selecting records before I cover the process of deleting records. Selecting One or More RecordsTo select a record, you simply click the gray record selector button to the left of a record within a form (see Figure 4.6). Access selects the record. Figure 4.6. The gray selector button.
Figure 4.7. The Orders table, with three records selected.If you want to select a single record when the cursor is within the record, you can simply select Edit | Select Record. Deleting Records from Within a FormWhen you know how to select records, deleting them is quite simple. The process is almost identical to that of deleting records in a datasheet:
The process of deleting a record is not so simple if you have established referential integrity between the tables in a database and the row that you are attempting to delete has child rows. Hour 9, "Creating Relationships," covers relationships and referential integrity. For now, you can think about the fact that customers generally have orders associated with them, and those orders have order detail records associated with them. The relationship between the Customers table and the Orders table prohibits the user from deleting customers who have orders. Here's how you delete a customer who has orders:
Access provides a referential integrity option with which you can cascade a deletion down to the child table. This means, for example, that if you attempt to delete an order, Access deletes the associated order detail records. If you establish referential integrity with the cascade delete option, the deletion process works like this:
Copying Records Within a FormAt times you may want to copy an entire record. This generally occurs because you are creating a new record and the new record is very similar to an existing record. For example, you might have two contacts at the same company who share similar information. You can copy the existing record and then make the necessary changes to the new record. Here's the process: Copying a record often results in what is called a referential integrity error. This occurs, for example, when copying a record would cause a duplicate primary key (that is, unique record identifier). In such a situation, you see an error message such as that displayed in Figure 4.11. You can either change the data in the field or fields that constitute the duplicate key, or you can press the Esc key to cancel the process of appending the new row. For example, in the example shown in Figure 4.11, you can modify the category name. Figure 4.11. A referential integrity error that appears when copying a record.Finding a Record That Meets Specific CriteriaIf you are editing records in a form, you need to find specific records quickly. The same procedure used in Datasheet view helps you to quickly locate data in a form:
Replacing Data in the Table Underlying a FormThere may be times when you want to update records that meet specific criteria. You might want to do this, for example, if a company changes its name or if you realize that you have improperly entered an employee's Social Security number. The Replace feature automatically inserts new information into the specified fields. Here's the process:
When using either Find or Replace, you can use several wildcard characters. A wildcard character is a character you use in place of an unknown character. Table 4.1 describes the wildcard characters.
|
[ Team LiB ] |