Delete confirmation


/ Published in: Visual Basic
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Dim intResponse As Integer
  2.  
  3. If IsNull(Me.VisitID) Then
  4. MsgBox "There is no visit to delete.", vbExclamation, "No Visit"
  5. Exit Sub
  6. Else
  7.  
  8. intResponse = MsgBox("Delete this visit record and all data", vbYesNo + _
  9. vbDefaultButton2 + vbQuestion, "Confirm Deletion?")
  10. If intResponse = vbYes Then
  11. DoCmd.SetWarnings False
  12. DoCmd.RunCommand acCmdDeleteRecord
  13. DoCmd.SetWarnings False
  14. End If
  15. End If
  16.  
  17. ''''''''''''''''''''
  18. ' BETTER DELETE CODE
  19. ''''''''''''''''''''
  20.  
  21. Private Sub Delete_Click()
  22. On Error GoTo Err_Delete_Click
  23.  
  24. If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
  25. DoCmd.SetWarnings False
  26. DoCmd.RunCommand acCmdSelectRecord 'this command is not normally needed
  27. DoCmd.RunCommand acCmdDeleteRecord
  28. End If
  29.  
  30. Exit_Delete_Click:
  31. DoCmd.SetWarnings True
  32. Exit Sub
  33.  
  34. Err_Delete_Click:
  35. If Err.Number = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
  36. DoCmd.SetWarnings True
  37. MsgBox "There is no record to delete.", vbCritical, "No record"
  38. Exit Sub
  39. ElseIf Err.Number = 2501 Then 'The RunCommand action was canceled
  40. DoCmd.SetWarnings True
  41. Exit Sub
  42. Else
  43. MsgBox Err.Number & " - " & Err.Description
  44. Resume Exit_Delete_Click
  45. End If
  46.  
  47. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.