The one other important type of Action query is the Update query. It can be used to change data in multiple records in a table at once. This is easier than changing the records one by one.
The Faculty table holds work phone numbers for each faculty member. All of these employees currently have the area code of 812. We have just received word that some of the employee phone numbers are being assigned new area codes. Each number with a 776 exchange, as in (812) 776-2488, will switch from the 812 area code to a 444 area code.
Changing each individual phone number manually would be very time consuming. We can design an Update query to indicate which numbers need to change and modify just the area code portion of the affected numbers in one action.
Step1. To create a new query, on the Ribbon,
Click the Create tab, Click
Step2. To add the table, in the Add Tables pane,
Double-Click tblFaculty
Step3. To add the Phone field to the query design window, in the field list,
Double-Click Phone
Step4. To select the Update Query type, on the Ribbon, in the Query Type group,
Click
Step5. To enter an expression to describe the numbers we will change, in the Criteria field, type:
Like "(812) 776*" Enter key
NOTE: Make sure to type a space between the (812) and the 776.
Step6. To access the Zoom tool for the Update To row, in the Phone column,
Right-Click the Update To field, Click Zoom...
Step7. To enter an expression to describe how the phone numbers will change, type:
"(444)"+Right([Phone],9)
Step8. To close the Zoom tool,
Click
Step10. To preview the query result,
Click
Testing the Update Query
To test the accuracy of the Update expression and its effect on the existing records, we will copy and paste the expression describing the changed numbers into a new field, change the query type back to Select query, and view the values displayed by the expression. We will see the result of the Update expression in the same way we saw the Weighted calculated field results earlier in this workshop.
Step1. To switch to Design View,
Click
Step2. To expand the first column,
Double-Click between the Phone column and the empty column after it
Step3. To select the Update To expression,
Press & Drag across "(444)"+Right([Phone],9)
Step4. To copy the expression, press:
Control key + C
Step5. To switch from an Update query to a Select query, in the Query Type group of the Ribbon,
Click
Step6. To create the second field, in the column to the right of the Phone field,
Click the top row, press: Control key + V, Enter key
Step 8. To view the query result,
Click
Step9. Verify that the 776 exchange phone numbers are updated to the 444 area code in the second column of the query results.
Running an Update Query
Now that we have confirmed the update will work as expected, we will switch the query type back to Update, and run the query.
Step1. To switch to Design View,
Click
Step2. To change the query type back to Update, on the Ribbon,
Click
Step3. To run the query, on the Ribbon,
Click
Step4. To continue with the update operation,
Click
Step5. To close the query without saving changes, at the top of the object workspace,
Right-Click the query tab, Click Close, Click
Viewing the Update
Let's check the results of the update in tblFaculty.
Step1. To see the effect of the Update query on faculty phone numbers, in the tables list,
Double-Click tblFaculty
Step2. To place the cursor, in the Phone column,
Click in any cell
Step3. To sort the records by phone number, on the Ribbon, in the Sort & Filter group,
Click
Step4. Close tblFaculty without saving.