Turning Events Off
In addition to canceling
operations by altering the status parameter of an event, you can also
turn the events off completely for an open instance of an object. By
setting any event’s status parameter to
adStatusUnwantedEvent, you are informing ADO that
you no longer want to be notified of a particular event.
To illustrate this ability, alter the WillMove event as shown:
Private Sub rst_WillMove(ByVal adReason As ADODB.EventReasonEnum, _
adStatus As ADODB.EventStatusEnum, _
ByVal pRecordset As ADODB.Recordset)
Debug.Print
Debug.Print " WillMove Event Raised"
adStatus = adStatusUnwantedEvent
Debug.Print " Turned WillMove Event Off"
End SubNow enter and execute a piece of code that raises the WillMove event at least once:
Debug.Print "--------- Before Opening Recordset"
rst.Open "Authors", _
"DSN=BiblioDSN"
Debug.Print
Debug.Print "--------- Before MoveFirst"
rst.MoveFirst
Debug.Print
Debug.Print "--------- Before MoveNext"
rst.MoveNext
Debug.Print
Debug.Print "--------- Before Closing Recordset"
rst.CloseWhen this code is executed, the following output is sent to the Immediate Window:
--------- Before Opening Recordset WillMove Event Raised Turned WillMove Event Off --------- Before MoveFirst --------- Before MoveNext --------- Before Closing Recordset
Note that once a Recordset object (or a Connection object for that matter) is closed and then reopened, the event will be raised again.
In the case of events that can be raised for more than one reason, you must indicate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access