ACC2000: How to Update a Table from a Second Table by Using an Expression (209246)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q209246
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).

SUMMARY

This article describes how to create a query that uses an expression to update a record in one table with data from another table.

MORE INFORMATION

The sample query below adds data from the Current Week table to the records in the Yearly Rainfall table.

NOTE: This type of query does not work if the data being added is the result of a totaling or grouping.

To perform the query, follow these steps:
  1. Start Microsoft Access and create a new blank database.
  2. Create a new table with the following fields and data, and then save it as Yearly Rainfall:
       Table: Yearly Rainfall
    
       City      Inches   LastUpdated
       -------------------------------
       Baroda     0.5     4/2/2000
       Basildon  22.0     4/2/2000
       Beaver    18.0     4/2/2000
    					
  3. Create a new table with the following fields and data, and then save it as Current Week:
       Table:  Current Week
    
       City      Inches   WeekOf
       --------------------------
       Baroda     0.1     4/9/2000
       Basildon   2.0     4/9/2000
       Beaver     2.5     4/9/2000
    					
  4. Create a new query based on the tables Yearly Rainfall and Current Week. Join the tables on the City field.
  5. On the Query menu, click Update Query.
  6. Drag the Last Updated and Inches fields from the Yearly Rainfall table to the query grid.
  7. Create the following entries in the Update To row of the query grid:
       Field: Last Updated
          Table: Yearly Rainfall
          Update To: [Current Week].[WeekOf]
       Field: Inches
          Table: Yearly Rainfall
          Update To: [Yearly Rainfall].[Inches]+[Current Week].[Inches]
    					
  8. Save the query, and then run it.

    The data in the table Yearly Rainfall is now as follows:
       City      Inches     Last Updated
       ---------------------------------
       Baroda     0.6       4/9/2000
       Basildon  24.0       4/9/2000
       Beaver    20.5       4/9/2000
    					

REFERENCES

For more information about update queries, click Microsoft Access Help on the Help menu, type troubleshoot update queries in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/29/2004
Keywords:kbhowto KB209246