• Delete Current Record (2000)

    Author
    Topic
    #448138

    I’m playing around with Access VBA which I find a little esoteric at the moment. I have placed a command button on a form without using the wizard and I wish it’s click event to delete the current record.
    I have the following line of code in the on click event:

    RunCommand acCmdDeleteRecord

    On clicking the button, it begins the delete process and asks me if I wish to proceed. When clicking the “No” option, an error message appears saying that the RunCommand action has been canceled and I can choose to debug or end.

    What do I need ti include to prevent this from happening?

    TIA

    Viewing 0 reply threads
    Author
    Replies
    • #1094982

      Hi Rob,

      If you want to suppress the error that occurs if the deletion is canceled, you must create an error handler:

      Private Sub cmdSomething_Click()
      On Error GoTo ErrHandler

      RunCommand acCmdDeleteRecord
      Exit Sub

      ErrHandler:
      If Err = 2501 Then
      ‘ Action canceled – do nothing
      Else
      ‘ Other error – report to user
      MsgBox Err.Description, vbExclamation
      End If
      End Sub

      • #1094984

        Hi Hans

        The impenetrable black cloud has now been replaced by a dense fog. grin

        thankyou

    Viewing 0 reply threads
    Reply To: Delete Current Record (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: