Share via


Visual Basic: DataGrid Control

BeforeUpdate Event

See Also   Example   Applies To

Occurs before data is moved from a DataGrid control to the control's copy buffer.

Syntax

Private Subobject**_BeforeUpdate(**[index As Integer,]****cancel As Integer)

The BeforeUpdate event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer that identifies a control if it is in a control array.
cancel A Boolean expression that determines if data is copied, as described in Settings.

Settings

The settings for cancel are:

Setting Description
True Leaves focus on control and doesn't copy data.
False (Default) Continues with copy operation and enables change of focus.

Remarks

When the user moves to another row or the Recordset object's Update method is executed, data is moved from the DataGrid control's copy buffer to the Data control's copy buffer and written to the database.

Just before the data is moved from the DataGrid control's copy buffer back into the Data control's copy buffer, the BeforeUpdate event is triggered. Unless the copy operation is canceled, the AfterUpdate event is triggered after the data has been moved back into the Data control's copy buffer and written to the database. The updated record is available by using the Bookmark property of the DataGrid control.

If you set the BeforeUpdate event cancel argument to True, focus remains on the control, neither the AfterUpdate or LostFocus event is triggered, and the record isn't saved to the database.

The BeforeUpdate event occurs before the AfterUpdate and LostFocus events for this control, or before the GotFocus event for the next control in the tab order.

This event occurs even if the control isn't bound.

Unlike the Change event, changing data in a control or record using code doesn't trigger this event.

You can use this event to validate data in a bound control record before permitting the user to commit the change to the Data control's copy buffer. By setting the cancel argument to True, the user can't move focus from the control until the application determines whether the data can be safely moved back to the Data control's copy buffer.