Delete Button

Iceolate

Registered User.
Local time
Today, 20:08
Joined
Oct 21, 2011
Messages
17
Hi
Is there any way for access to keep the record to be deleted on the screen after the Delete button has been pressed until the user clicks the Yes button to confirm deletion?

(My first post)
 
You'd have to create your own Delete Button and 'disarm' the normal Delete option from the Menu:

At the top of the Code Module for your Form, immediately after the

Code:
[B]Option Compare Database[/B]

statement, or whichever Option Statement you're using, place this line

Code:
[B]Dim CompleteDelete As Boolean[/B]

Now, to turn off deleting, unless the custom button is used, place this code into the Module
Code:
Private Sub Form_Delete(Cancel As Integer)
 
 If CompleteDelete <> True Then
  Cancel = True
 End If
 
 CompleteDelete = False
 
End Sub
Now, behind the custom delete button:
Code:
Private Sub cmdDeleteRecord_Click()
   
 Resp = MsgBox("Are you sure you want to Delete this Record?", vbYesNo + vbDefaultButton1)
 
 DoCmd.SetWarnings False
 
 If Resp = vbYes Then
  CompleteDelete = True
  DoCmd.RunCommand acCmdSelectRecord
  DoCmd.RunCommand acCmdDeleteRecord
 End If

DoCmd.SetWarnings True

End Sub
I've tested this with every combination of deleting/not deleting using both the custom button and the Delete from the Menu and I believe it covers all possibilities. You could, of course, simply remove the Delete Option from the Menu, but that would be a bit more work, and I prefer not messing around with the native Menus unless I'm going to use all Custom Menus on a particular app.

Linq ;0)>
 
Thank you Linq for your reply. I will work through your code and give it a go.
First forum question and got a reply... impressed ;-)
 
That's why we're here! Things tend to run slower on weekends, as many responders do so during their business hours, but I've been in forced retirement for 6 years now, and one day is pretty much like the next!

Good luck with your project!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom