
ADO WillChangeField event: can't cancel change by changing adStatus
I'm having difficulty understanding ADO events. Using the WillChangeField
event I can't seem to cancel a field change operation permanently by setting
adStatus to adStatusCancel, as I understand from the literature [wrongly?]
that it should. Can someone explain what I'm doing wrong please?
Drag a DataEnvironment recordset-returning command (MyRecordset) onto a
form, so as to automatically create a set of textboxes etc. Add a couple of
navigation buttons and code them to MoveNext / MovePrevious the recordset.
Put this in the form's code:
Dim Withevents rst as Recordset
Private Sub Form_Load()
Set rst = DE.rsMyRecordset
End Sub
Private Sub rst_WillChangeField(ByVal cFields As Long, ByVal Fields As
Variant, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As
ADODB.Recordset)
If MsgBox("Proceed or Cancel?", vbOKCancel) = vbCancel Then adStatus =
adStatusCancel
End Sub
When this is run, I make changes to a textbox, then click a navigation
button. The messagebox appears, and I click Cancel. The textbox stays in its
changed state. I click a navigate again, and get the messagebox again. If I
click Cancel again, I get an error (Operation was cancelled): if I click OK,
the textbox reverts to its unchanged state and then moves to the next
record.
Do I need to trap the adStatusErrorsOccurred in a later event and run the
field change again with original data? I've tried doing this at various
stages in the event sequence but I think I'm missing some essential truth
about ADO here...
Jonathan
PS using VB6, ADO 2.5, Access2000. MyRecordset is BatchOptimistic.
PPS Why not just use the textbox's Validate event? Because in practice, the
WillChangeField event is being trapped in a separate 'wrapper' class around
the recordset that is doing several other things when this, or any other,
textbox control tries to change a field.