UPDATE Statement (Microsoft Access SQL)
Creates an update query that changes values in fields in a specified table based on specified criteria.
UPDATE table SET newvalue WHERE criteria;
The UPDATE statement has these parts:
The name of the table containing the data you want to modify.
An expression that determines the value to be inserted into a particular field in the updated records.
An expression that determines which records will be updated. Only records that satisfy the expression are updated.
UPDATE is especially useful when you want to change many records or when the records that you want to change are in multiple tables.
You can change several fields at the same time. The following example increases the Order Amount values by 10 percent and the Freight values by 3 percent for shippers in the United Kingdom:
UPDATE Orders SET OrderAmount = OrderAmount * 1.1, Freight = Freight * 1.03 WHERE ShipCountry = 'UK';
This example changes values in the ReportsTo field to 5 for all employee records that currently have ReportsTo values of 2.
Sub UpdateX() Dim dbs As Database Dim qdf As QueryDef ' Modify this line to include the path to Northwind ' on your computer. Set dbs = OpenDatabase("Northwind.mdb") ' Change values in the ReportsTo field to 5 for all ' employee records that currently have ReportsTo ' values of 2. dbs.Execute "UPDATE Employees " _ & "SET ReportsTo = 5 " _ & "WHERE ReportsTo = 2;" dbs.Close End Sub