Delete current record in form using input box confirmation (1 Viewer)

robyholmes

Registered User.
Local time
Today, 13:54
Joined
Mar 2, 2009
Messages
57
Hi

I would like to delete a record currently open in a form (With a filter on the current record if that matters)

I have used this code:
Code:
If InputBox("Type 'Delete' to delete the customer", "Delete Customer") = "Delete" Then
         DoCmd.RunCommand acCmdDeleteRecord
End If

But I get 'Command or action not available now'? Can you explain why?

Thanks
Rob Holmes
 

HiTechCoach

Well-known member
Local time
Today, 07:54
Joined
Mar 6, 2006
Messages
4,357
You need to select the current record before you can delete it.


Try something like:

Code:
Private Sub cmdDelete_Click()

  On Error GoTo Err_cmdDelete_Click

  DoCmd.SetWarnings False
  If MsgBox("Confirm deletion of the record?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
    DoCmd.RunCommand [b]acCmdSelectRecord[/b]
    DoCmd.RunCommand acCmdDeleteRecord
  End If

Exit_cmdDelete_Click:

  DoCmd.SetWarnings True
  Exit Sub

Err_cmdDelete_Click:

  MsgBox Err.Description
  Resume Exit_cmdDelete_Click

End Sub
 

robyholmes

Registered User.
Local time
Today, 13:54
Joined
Mar 2, 2009
Messages
57
Thanks a lot, will get home tomorrow and give it a try. Thanks!
 

Users who are viewing this thread

Top Bottom