Results 1 to 3 of 3

Thread: ADO events

  1. #1
    Guest

    Unhappy

    Could someone please help me out with this?

    I am trying to use the WillChangeRecord event for the recordset.delete method.

    Everything seems fine unless I set the adStatus to adStatusCancel. If I do that my program generates a run-time error that I do not seem to be able to handle.

    Any idea?

    Thanks

    GG

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374
    how about posting your code and a description of the error and where in the code it occurs

  3. #3
    Guest
    Good idea.

    Here it comes...

    Public Sub Delete()
    'On Error GoTo Err_Delete

    With adoPrimaryRS
    If .Supports(adDelete) Then
    adoPrimaryRS.Delete
    MoveNext
    Else
    MsgBox "Impossibile cancellare il record"
    End If
    End With

    Exit_Delete:
    Exit Sub

    Err_Delete:
    MsgBox Err.Number & Err.Description
    Resume Exit_Delete

    End Sub

    Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    'Posizione in cui inserire il codice per la convalida
    'L'evento viene richiamato in seguito alle seguenti azioni
    Dim bCancel As Boolean

    Select Case adReason
    Case adRsnAddNew
    Case adRsnClose
    Case adRsnDelete
    'The user is trying to delete a record from the database

    'Asks before delete a record.
    strMsgBoxText = "Il record selezionato sta per essere cancellato!" & vbCrLf & _
    "Continuare?"
    strMsgBoxTitle = "Attenzione!"

    intMsgBoxResponse = MsgBox(strMsgBoxText, vbApplicationModal + vbDefaultButton2 + _
    vbExclamation + vbYesNo, strMsgBoxTitle)

    'The user chose no to delete the record from the database
    If intMsgBoxResponse = vbNo Then bCancel = True

    Case adRsnFirstChange
    Case adRsnMove
    Case adRsnRequery
    Case adRsnResynch
    Case adRsnUndoAddNew
    Case adRsnUndoDelete
    Case adRsnUndoUpdate
    Case adRsnUpdate
    End Select

    If bCancel Then adStatus = adStatusCancel

    End Sub

    I have starte questioning whether I should ask the operator to confirm his intent to delete the record before call the .delete method. It seems to me that would make more sense. It still remain though that the code above does not work on my machine. Here's the run-time error I get

    -2147217842 (80040e4e)
    The change was canceled during notification; no columns are changed.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width