The Data_Validate event is called just prior to saving changes on disk. It is called as a result of the Update method, or any of the Move methods. It receives an argument called Save, which is True or False. If Save is True, a change has occurred to at least one bound control, and that change will be saved to disk. You can change the value of Save in your event, either to force the data to be saved or to cause it not to be saved.The Data_Validate event also receives an argument called Action, which tells which action triggered the validate event (such as MoveNext, Update, etc.). You can inspect Action, and change its value if necessary. For example, setting Action to 0 cancels the intended action. See your VB Programmer's Guide for a list of action values, and for a full description of Data_Validate.TIP: Use the Data_Validate event to take the content of unbound controls and put the information into your database. To do so, your Data_Validate event should take the contents of an unbound control and store it into a valid field in your database. You would also program any event that causes a Reposition (MoveNext, etc.) to take the field data and put it into the unbound control.
EXAMPLE - "binding" a Combo Box to a datafield
(general) (declarations)
Dim Repositioning as IntegerSub Data1_Reposition
Repositioning = True
Combo1.Text = Data1.RecordSet!State
Repositioning = False
End SubSub Data1_Validate
'take the contents of the combo box and put it into a valid data field.
'I used "State", but it should be something valid for your database
Data1.RecordSet!State = Combo1.Text
End SubSub Combo1_Change
' assume txtName is a text box that is bound to the data control
' setting DataChanged to True will "trick" the data control into an update
If Repositioning Then Exit Sub
txtName.DataChanged = True
End Sub
大意是说用Data1_Reposition事件显示数据,用Data1_Validate事件更新数据。