Validate Event (Data Control)

       

Occurs before a different record becomes the current record; before the Update method (except when data is saved with the UpdateRecord method); and before a Delete, Unload, or Close operation.

Syntax

Private Sub object_Validate ([ index As Integer,] action As Integer, save As Integer)

The Validate event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index Identifies the control if it's in a control array.
action An integer that indicates the operation causing this event to occur, as described in Settings.
save A Boolean expression specifying whether bound data has changed, as described in Settings.

Settings

The settings for action are:

Constant Value Description
vbDataActionCancel 0 Cancel the operation when the Sub exits
vbDataActionMoveFirst 1 MoveFirst method
vbDataActionMovePrevious 2 MovePrevious method
vbDataActionMoveNext 3 MoveNext method
vbDataActionMoveLast 4 MoveLast method
vbDataActionAddNew 5 AddNew method
vbDataActionUpdate 6 Update operation (not UpdateRecord)
vbDataActionDelete 7 Delete method
vbDataActionFind 8 Find method
vbDataActionBookmark 9 The Bookmark property has been set
vbDataActionClose 10 The Close method
vbDataActionUnload 11 The form is being unloaded

The settings for save are:

Setting Description
True Bound data has changed
False Bound data has not changed

Remarks

These constants are listed in the Visual Basic (VB) object library in the Object Browser.

The save argument initially indicates whether bound data has changed. This argument can still be False if data in the copy buffer is changed. If save is True when this event exits, the Edit and UpdateRecord methods are invoked. Only data from bound controls or from the copy buffer where the DataChanged property is set to True are saved by the UpdateRecord method.

This event occurs even if no changes have been made to data in bound controls and even if no bound controls exist. You can use this event to change values and update data. You can also choose to save data or stop whatever action is causing the event to occur and substitute a different action.

You can change the action argument to convert one action into another. You can change the various Move methods and the AddNew method, which can be freely exchanged (any Move into AddNew, any Move into any other Move, or AddNew into any Move). When using AddNew, you can use MoveNext and then execute another AddNew to examine the EditMode property to determine if an Edit or AddNew operation is in progress. Attempting to change AddNew or one of the Moves into any of the other actions is either ignored or produces a trappable error. Any action can be stopped by setting action to 0.

In your code for this event, you can check the data in each bound control where DataChanged is True. You can then set DataChanged to False to avoid saving that data in the database.

You can't use any methods (such as MoveNext) on the underlying Recordset object during this event.