Return to Snippet

Revision: 9145
at May 17, 2011 03:08 by heislekw


Updated Code
Dim intResponse As Integer
    
    If IsNull(Me.VisitID) Then
        MsgBox "There is no visit to delete.", vbExclamation, "No Visit"
        Exit Sub
    Else
    
    intResponse = MsgBox("Delete this visit record and all data", vbYesNo + _
        vbDefaultButton2 + vbQuestion, "Confirm Deletion?")
    If intResponse = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings False
    End If
    End If

''''''''''''''''''''
' BETTER DELETE CODE
''''''''''''''''''''

Private Sub Delete_Click()
On Error GoTo Err_Delete_Click

   If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
      DoCmd.SetWarnings False
      DoCmd.RunCommand acCmdSelectRecord 'this command is not normally needed
      DoCmd.RunCommand acCmdDeleteRecord
   End If

Exit_Delete_Click:
   DoCmd.SetWarnings True
   Exit Sub

Err_Delete_Click:
   If Err.Number = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
      DoCmd.SetWarnings True
      MsgBox "There is no record to delete.", vbCritical, "No record"
      Exit Sub
   ElseIf Err.Number = 2501 Then 'The RunCommand action was canceled
      DoCmd.SetWarnings True
      Exit Sub
   Else
      MsgBox Err.Number & " - " & Err.Description
      Resume Exit_Delete_Click
End If

End Sub

Revision: 9144
at December 31, 2010 03:16 by heislekw


Updated Code
Dim intResponse As Integer
    
    If IsNull(Me.VisitID) Then
        MsgBox "There is no visit to delete.", vbExclamation, "No Visit"
        Exit Sub
    Else
    
    intResponse = MsgBox("Delete this visit record and all data", vbYesNo + _
        vbDefaultButton2 + vbQuestion, "Confirm Deletion?")
    If intResponse = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings False
    End If
    End If

Revision: 9143
at October 22, 2008 16:45 by heislekw


Initial Code
Dim iresponse As Integer
iresponse = MsgBox("Are you sure you want to delete this records?" & _
    Chr(13) & Chr(13) & "Continue?", 4 + 32 + 256, "Confirm Delete")
If iresponse = 7 Then
Exit Function
Else
End If

Initial URL


Initial Description


Initial Title
Delete confirmation

Initial Tags


Initial Language
Visual Basic