4. Copying Records Within a Form
Copy Entire Records
At times, you 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:
1. | Select
the record you want to copy. You can select the record by clicking the
gray record selector or by choosing Select from the Find group on the
Home tab of the ribbon and then choosing Select from the drop-down menu.
|
2. | Select Copy in the Clipboard group on the Home tab of the Ribbon.
|
3. | Select
Paste in the Clipboard group on the Home tab of the Ribbon, and then
choose Paste Append from the drop-down. Access copies the original
record and places you in the new record (the copy).
|
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 8.
You can either change the data in the field or fields that constitute
the duplicate key or you can press the Escape key to cancel the process
of appending the new row. For example, in the example shown in Figure 8, you can modify the company name.
5. Finding a Record That Meets Specific Criteria
If
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:
1. | Select the field that contains the criteria for which you are searching (in this case, Salesperson).
|
2. | Click the Find button in the Find group on the Home tab of the Ribbon. The Find and Replace dialog box appears (see Figure 9).
|
3. | Type the criteria in the Find What text box. For this example, type Nancy Freehafer.
|
4. | Use
the Look In drop-down list box to designate whether to search only the
current field or all fields in the table. For this example, designate
that you want to search only the current field.
|
5. | Use
the Match drop-down list box to designate whether to match any part of
the field you are searching, the whole field you are searching, or the
start of the field you are searching. For example, if you type the word Federal
in the Find What text box and you select Whole Field in the Match
drop-down list box, you find only entries where Ship Via is set to
Federal. If you select Any Part of Field, you find Federal Shipping,
Federal Express, United Federal Shipping, and so on. If you select Start
of Field, you find Federal Shipping and Federal Express, but you do not
find United Federal Shipping. For this example, designate that you want
to match the whole field.
|
6. | Use
the Search drop-down list box to designate whether to search only up
from the current cursor position, only down, or in all directions. For
this example, designate that you want to search in all directions.
|
7. | Use the Match Case check box to indicate whether you want the search to be case sensitive.
|
8. | Use
the Search Fields as Formatted check box to indicate whether you want
to find data only based on the display format (for example, 17-Jul-96
for a date).
|
9. | Click the Find Next button to find the next record that meets the designated criteria.
|
10. | To
continue searching after you close the dialog box, use the Shift+F4
keystroke combination or select Find again from the Ribbon.
|
Replace Data in the Table Underlying a Form
Sometimes you might want to update records that meet
specific criteria. You might want to do this, for example, if a company
changes its name or 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:
1. | Click within the field that contains the criteria you are searching for (Job Title for this example).
|
2. | Click the Replace button in the Find group on the Home tab of the ribbon. The Find and Replace dialog box appears.
|
3. | Select the Replace tab (see Figure 10).
|
4. | Type the criteria in the Find What text box. Type Owner for this example.
|
5. | Type the new information (the replacement value) in the Replace With text box. Type CEO for this example.
|
6. | Choose
values for the Look In drop-down list box, Match drop-down list box,
Search drop-down list box, Match Case check box, and Search Fields as
Formatted check box.
|
7. | Click the Find Next button. Access locates the first record that meets the criteria designated in the Find What text box.
|
8. | Click the Replace button.
|
9. | Repeat
steps 7 and 8 to find all occurrences of the value in the Find What
text box and replace them. As an alternative, you can click the Replace
All button to replace all occurrences simultaneously.
You should use Replace All with quite a bit of caution. Remember that the changes you make are permanent.
Although Replace All is a viable option, when you use it, you need to
make sure you have a recent backup and that you are quite certain of
what you are doing. In fact, I usually do a few replaces to make sure
that I see what Access is doing before I click Replace All.
|
|
10. | Click Cancel when you’ve finished.
|
If you are searching a very large table, Access can
find a specific value in a field fastest if the field you are searching
on is the primary key or an indexed field.
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 1 describes the wildcard characters.
Table 1. Wildcard Characters You Can Use When Searching
Wildcard Character | Description |
---|
* | Acts as a placeholder for multiple characters |
? | Acts as a placeholder for a single character |
# | Acts as a placeholder for a single number |