Delete Current Record

gselliott

Registered User.
Local time
Today, 20:00
Joined
May 17, 2002
Messages
106
I am having problems deleting a current record using VB Code.

I am able to delete it however i dont want the message box that lets the user select Yes or No, i just want it to delete it without asking or use the OK button.

Is there anyway of doing this? Any help would be appreciated.

Thanks
 
Haven't tried it myself, but have you tried:
DoCmd.SetWarnings False
Or deleting the record using SQL?
 
Cheers the Docmd.SetWarnings False worked a treat!
 
Just in case the user clicks the button by mistake... Are you sure that you do
not want to give the user the choice if they want to delete the current record?
Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
    
    Beep
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.Setwarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.Setwarnings True
    End If
    
Exit_bDelete_Click:
    Exit Sub
    
Err_bDelete_Click:
    If Err = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        Beep
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub
Adding some fields to the message box so that you are identifying some parts of the
current record is also a nice touch for the user to see.

HTH
 
Great I'm also looking for this.. What if my delete is in the form then i attach a subtable to it, how would i delete the selected record on the table? Sorrie to interupt...
 

Users who are viewing this thread

Back
Top Bottom