ADO WillChangeField event: can't cancel change by changing adStatus 
Author Message
 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.



Wed, 12 Nov 2003 18:24:35 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Setting adStatus in WillChangeField event does not work

2. Changing control name of button doesn't change event name to be the same

3. How to cancel change event?

4. Tabcontrol 'change' event

5. Changing properties of a Collection with a change event :/ <--- pls help

6. Changing properties of a Collection with a change event :/ <--- pls help

7. ComboBox Change Event Does not fire when user changes selection

8. Label Caption Doesn't Change When Changed

9. DB Combo doesn't fire Change event?

10. Q: Can't change pointer to hourglass in ColumnClick event of a List View control

11. Combo Box Change Event Doesn't Work

12. MouseDown event - Shift value doesn't change

 

 
Powered by phpBB® Forum Software