/ Published in: Visual Basic
Expand |
Embed | Plain Text
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
You need to login to post a comment.
