how do I create a delete button in access 2007?

Posted on 2009-02-16
Last Modified: 2012-05-06
I have created a database and I have created several command buttons: new, delete and search. I have managed to get the delete and ew buttons working however struggling to create a delete button. Any ideas would be aprriciated.

Question by:IanGurden
    LVL 75

    Accepted Solution

    You basically need these four pieces to implement deleting a record:

    Button on form to Delete:
    Private Sub cmdDelete_Click()
        DoCmd.RunCommand acDeleteRecord  ' This will trigger the Form_Delete event below.
    End Sub

    This code in the following three Form events:

    Private Sub Form_Delete(Cancel As Integer)
        'This message or something similar
        If MsgBox(""Are you SURE you want to DELETE this record?." & Chr(13) & "This operation cannot be undone", 292, "Delete Record") <> vbYes Then
            Cancel = True
        End If  
    End Sub

    Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
      Response = acDataErrContinue
    End Sub

    Private Sub Form_AfterDelConfirm(Status As Integer)    
    End Sub
    LVL 46

    Assisted Solution

    Hi Ian,

    Have a look at the following

    Good Luck!


    Author Comment

    I have tried adding the above code however it doesn't seem to work and i can't see why.
    LVL 13

    Expert Comment

    are the cmdDelete_Click(), Form_Delete(Cancel As Integer), Form_BeforeDelConfirm(Cancel As Integer, Response As Integer),Form_BeforeDelConfirm(Cancel As Integer, Response As Integer) and Form_AfterDelConfirm(Status As Integer)      all set to [Event Procedure] in the events tab of the properties window?

    Author Comment

    Don't know.... there all set to event procedure once i clicked save.
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    "however it doesn't seem to work"

    Well, I have the code in hundreds of places for many years ... so I can pretty much guarantee you it works.

    What exactly is not 'working' ?? Can you be specific?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now