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 1.
This will select the record whose TourID is "1," but what about the rest?
Press the (down arrow key) to select the Criteria row (the or row) and type 2.
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 Criteria row, type 3, press the (down arrow key) to select the Criteria row and type 9.
Compare your query to the one in Figure 6-36. 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 6-37.
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 6-38. Notice that the prices of four European tours have been increased by ten percent.
Close the tblTours table and close the database.