• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 936
  • Last Modified:

how do I create a delete button in access 2007?

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.

Thankyou
0
IanGurden
Asked:
IanGurden
2 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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)
    Beep
    '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)    
    Me.Requery
    DoEvents
End Sub
---------------
mx
0
 
tbsgadiCommented:
Hi Ian,

Have a look at the following
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_22757713.html



Good Luck!

Gary
0
 
IanGurdenAuthor Commented:
I have tried adding the above code however it doesn't seem to work and i can't see why.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
Surone1Commented:
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?
0
 
IanGurdenAuthor Commented:
Don't know.... there all set to event procedure once i clicked save.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"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?

mx
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now