Delete Current Record - cmdButton

indesisiv

Access - What's that?
Local time
Today, 04:39
Joined
Jun 13, 2002
Messages
265
Hi All,

I know it shouldn't be that difficult but

I am trying to just have a button to delete the record that the user is on at that moment in time.

I am sure that it is something to with recordset.delete but i may be miles of.

Any help would be greatly received.

Steve
 
Try using the button wizard, it has a default delete button...

Regards
 
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.RunCommand acCmdDeleteRecord
    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
 

Users who are viewing this thread

Back
Top Bottom