About batch transactions

In a Microsoft Access project, you can ensure data integrity for insert, update, and delete operations on multiple records by creating a bound form that uses a batch transaction.

What is a batch transaction?

A batch transaction guarantees that information in the database is logically consistent at all times, even when a single logical operation contains multiple database operations. Access and SQL Server treat all database changes inside a transaction as a single unit of work. By definition, either an entire transaction is completed safely and all resulting changes are reflected in the database, or the transaction is rolled backùand all changes to the database are undone. Consistency and recoverability of a database transaction are guaranteed even in the case of system failure in the middle of complex updates by more than one user.

Without a batch transaction, each record is saved to the database independently, which can make it very difficult to ensure data integrity for a single logical operation. With a batch transaction, you can ensure one of two things: either all changes are made or no changes are made to the server database for a single logical operation.

For example, without a batch transaction, a user entering a new order on a form in the Northwind database saves the order information, and then each line item one at a time. A second user running a report while an order is partially complete will see incorrect order information, such as an order with no line items or one line item instead of two. With a batch transaction, the second user will only see a report that contains either the complete order information or none of the order information.

When you update a form in a batch transaction, three things can occur:

Enabling a batch transaction

The following are requirements for creating and using batch transactions in Microsoft Access:

Changing the default behavior when you save records in a batch transaction

By default, Access attempts to commit records when a user navigates off a master record (in a main form/subform combination), closes the form, or clicks Save All Records on the Records menu.

However you can use two additional properties to change the Access default behavior for batch transactions:

If you set the Batch Updates property to Yes, by default, the value of Commit On Close is set to Yes and Commit On Navigation is set to No. This means a user can commit only when the form or main form is closed, or a user clicks the Save All Records command on the Records menu. A user won't commit when navigating off the master record unless the value of Commit On Navigation is Yes.

If you set both the Commit On Close property and Commit on Navigate property to No, this means that the user can close the form and lose any updated records without the default warning message. In this case, a developer should add a "Save All Records" button to the form so that the user can save changes, or instruct the user to use the Save All Records command on the Records menu.