The next stage is to add our MoveComplete
event. Here, we will be defining a standard MoveComplete
that is built into an ADO data control. If you drew an ADO Data control on your form and double-clicked to open the code window to look at the code, this event would be there. Here, we are simply adding this same event to our code. And since we declared the recordset with the keyword WithEvents
, this event will fire in our class just as it would if you used an ADO data control. We must get the 'signature' correct, so be sure you add this exactly as shown.
6. Add the following code to the adoPublishers_MoveComplete
private subroutine in our class module. Even though this looks like a lot of code, we are simply reading the values of the adReason
and adStatus
parameters that are passed into the event by VB, and displaying them to the user if they have checked the check box on the frmBoundExample
form. Add the highlighted code now:
Private Sub adoPublishers_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, _ ByVal pError As ADODB.Error, adstatus As ADODB.EventStatusEnum, _ ByVal pRecordSet As ADODB.Recordset)
Dim sMessage As String
Dim iIndx As Integer
If showInfo = True Then
sMessage = "Reason: "
Select Case adreason
Case adRsnAddNew
sMessage = sMessage & "Adding New Record" & vbCrLf
Case adRsnClose
sMessage = sMessage & "Closing Recordset" & vbCrLf
Case adRsnDelete
sMessage = sMessage & "Deleting Record" & vbCrLf
Case adRsnFirstChange
sMessage = sMessage & "First Change" & vbCrLf
Case adRsnMove
sMessage = sMessage & "Move" & vbCrLf
Case adRsnMoveFirst
sMessage = sMessage & "Move First Record" & vbCrLf
Case adRsnMoveLast
sMessage = sMessage & "Move Last Record" & vbCrLf
Case adRsnMoveNext
sMessage = sMessage & "Move Next Record" & vbCrLf
Case adRsnMovePrevious
sMessage = sMessage & "Move Previous" & vbCrLf
Case adRsnRequery
sMessage = sMessage & "Requering" & vbCrLf
Case adRsnResynch
sMessage = sMessage & "Resynch" & vbCrLf
Case adRsnUndoAddNew
sMessage = sMessage & "Undo Adding New Record" & vbCrLf
Case adRsnUndoUpdate
sMessage = sMessage & "Undoing Update" & vbCrLf
Case adRsnUpdate
sMessage = sMessage & "Updating record" & vbCrLf
End Select
sMessage = sMessage & "Status: "
Select Case adstatus
Case adStatusCancel
sMessage = sMessage & "Cancel" & vbCrLf
Case adStatusCantDeny
sMessage = sMessage & "Cant Deny" & vbCrLf
Case adStatusErrorsOccurred
sMessage = sMessage & "Errors Occured" & vbCrLf
Case adStatusOK
sMessage = sMessage & "Ok" & vbCrLf
Case adStatusUnwantedEvent
sMessage = sMessage & "Unwanted Event" & vbCrLf
End Select
iIndx = MsgBox(sMessage, vbOKOnly + vbInformation, _
"Bound Data Class MoveComplete")
End If
End Sub
So as you can see, the only real code here is in the two Select
statements. We are checking the enumerated values of the adReason
and adStatus
variables passed into the event and displaying them to the user (I just wanted to show you what these items were and how you can grab them if you need to read them).