Just like other action queries, you create an update query by first creating a select query and then converting the select query to an update query.
Access asks you to confirm the record update.
The update query
In this lesson you will create an update query to raise the prices of all trips to Europe by 10 percent.
From the Database window, click the Queries icon in the Objects bar and click the New button.
The New Query dialog box appears.
Select Design View and click OK.
The query design window and Show Table dialog box both appear. Here you have to select the tables and/or queries you want to use in the update query.
Double-click the tblTours table and click Close.
Now you need to convert the select query to an update query. Here's how:
Click the Query Type button list arrow and select Update Query from the list.
Access converts the select query to an update query. Notice an Update To row appears in the design grid. Now you have to specify the fields you want to update.
Double-click the TourID, Normal Price, and First Class Price fields in the tblTours field list.
The next step is a little bit trickyyou have to tell Access which fields to update and how to update them. You want to raise the price of both the Normal Price and First Class Price fields by 10 percentyou will have to write an expression (or formula) in the Update To rows of both fields to make this little bit of magic happen.
Click the Normal Price column's Update To row and type
[Normal Price]+([Normal Price]*.1).
So what does this confusing expression actually mean? Let's assume the Normal Price for a record is $100. The expression would then look something like this: [$100] + ([$100] * .1).
Access first calculates anything it sees in parentheses, so it multiples $100 x 0.1 (or 10%) and comes up with $10. Access then adds this $10 to the Normal Price (as in $10 + $100) and comes up with $110. Make a little more sense? Hope sobecause you have to do the same thing to the First Class Price field.
Click the First Class Price column's Update To row and type:
[First Class Price]+([First Class Price]*.1).
Next you need to specify any limiting criteria. You want to raise prices for only those tours that are in Europe. Sadly, the only way to determine this is by looking at the values in the tblTours table. Here are all the European TourIDs: 1, 2, 3, and 9. You will have to create an OR statement in your query to make sure you get them all.
Click the TourID field's Criteria row and type
This will select the record whose TourID is "1," but what about the rest?
Press the (down arrow key) to select the TourID field's second Criteria row (the or row) and type
This will select the records whose TourID is "2." Go to the next step and finish adding the rest of the OR criteria.
Press the (down arrow key) to select the TourID field's third Criteria row, type
3, press the (down arrow key) to select the TourID field's fourth Criteria row and type
Compare your query to the one in figure. Look the same? Let's run the query.
Click the Run button on the toolbar.
Access asks about the updating the selected records, as shown in figure.
Access updates the selected records by raising both their Normal Price and First Class Price fields by 10 percent. Let's open the new table.
Close the query without saving your changes, click the Tables icon in the Objects bar, and double-click the tblTours table.
Compare your table with figure. Notice that the prices of four European tours have been increased by ten percent.
Close the tblTours table and close the database.
To create an update query:
create a new query in design view, then select the tables and/or queries you want to use in the update query.
click the query type button list arrow on the toolbar and select update query.
select query » update query from the menu.
double-click the fields that you want to appear in the query or click and drag the fields onto the design grid.
enter an expression to update the selected field.
enter any criteria, if needed, to select which records should be updated.
click the view button to view the results of the update query.
if you're satisfied that the appropriate records will be updated, click the run button on the toolbar and click yes to confirm the update.