About updating data in a Microsoft Access project or data access page

About updating data in a Microsoft Access project or data access page

The way Microsoft Access updates data in a Microsoft Access project or data access page is different from the way they update data in a Microsoft Access database. Both users and programmers need to be aware of these differences. This topic provides reference information about:

General rules for updating data

Working with updatable snapshots

When updated field values are displayed

Recommended ways to update related data

General rules for updating data

The following rules apply when you are updating data from an Access project or page connected to either an Access database or Microsoft SQL Server database:

Return to top

Working with updatable snapshots

Access 2000 supports only inserting, deleting, and updating data in the row of a unique table (the "many" side of a join) in an updatable snapshot that has been created by a one-to-many join operation in a view, row-returning stored procedure, or SQL statement. Access 2000 doesn't allow you to update fields on the one side of the join.

A Form or page that is based on a one-to-many join must define the UniqueTable property in order for the recordset to be updatable. The unique table (also called the "most-many" table) is the "many" side of a one-to-many relationship. It is called a unique table because one record from the unique table corresponds to, at most, one record in the view, row-returning stored procedure, or SQL statement. For example, in a view that joins the Customers and Orders tables, Orders is the unique table because one record from the Orders table corresponds to, at most, one unique record in the view. By contrast, one record in the Customers table, can correspond to multiple records in the view.

Additionally, for a record source that is a stored procedure or SQL statement containing parameter markers, if you want to display the current values of a record after it is updated, you must also set the ResyncCommand property. Note that if you don't set the ResyncCommand property in these cases, the only consequence is that you won't see current values in a record after an update or insert. The update or insert will still happen correctly. For other types of record sources, Access displays current values even if the ResyncCommand property is not set.

In an updatable snapshot, you see only current values in an edited or newly inserted record after it has been successfully saved (See discussion below). For example, the Orders table contains an identity column as its primary key. When you insert into this table, the new OrderID value appears after you save the record or move to another record (which implicitly saves the record). Similarly, in a form based on a view joining Customers and Orders, if you update the OrderID field to a different CustomerID, the Address field will not show the address of the new customer until after the record has been saved.

Finally, all key fields or the UniqueTable must be in the SQL statement select list (although not necessarily visible). You must also select all NOT NULL columns that do not have server defaults defined, and supply values for these columns in the recordset except for fields with the Identity property set.

Return to top

When updated field values are displayed

In general, when you are updating fields in a form, datasheet, or page, Access can automatically insert a value for you, such as a default value, a calculated field, a timestamp value, an identity/AutoNumber field, or action performed by a trigger. However, unlike an Access database, the display of the value or effect of the operation occurs after you commit the record. This occurs because Access must update or perform the operation at the server first and then refresh the current display on the client.

Return to top

Recommended ways to update related data

The following are recommended ways to update related data:

Return to top