How can I remove the pesky "The runCommand action was canceled" dialog box after a "cancel = true" statement

adanthuis

On the Form_beforeupdate() event of my form "Alias" I have this...

If IsNull(Me.txtFName) And IsNull(Me.txtLName) Then
MsgBox "You must enter a contact!", vbokayonly, "Contact"
Cancel = True
End If

Anytime this cancels a runCommand code such as...

DoCmd.RunCommand acCmdSaveRecord 

a dialog appears telling me that it was canceled. Is there a way to suppress those dialogs?

HansUp

You can add an error handler to trap and ignore error 2501, which is triggered when the form's Before Update event cancels DoCmd.RunCommand acCmdSaveRecord

The following example is from my form which has a command button to save the current record. It suppresses that "RunCommand action was canceled" message as I think you wish.

Since your form's code apparently calls DoCmd.RunCommand acCmdSaveRecord from multiple locations, replace each of those calls with SaveRecord as I did in cmdSave_Click().

Option Compare Database
Option Explicit ' <-- NEVER troubleshoot VBA code without this!!!

Private Sub cmdSave_Click()
    'DoCmd.RunCommand acCmdSaveRecord
    SaveRecord
End Sub

Private Sub SaveRecord()
    Dim strMsg As String

On Error GoTo ErrorHandler

    DoCmd.RunCommand acCmdSaveRecord

ExitHere:
    Exit Sub

ErrorHandler:
    Select Case Err.Number
    Case 2501 ' The RunCommand action was canceled.
        ' do nothing --> just ignore the error
    Case Else
        ' notify user about any other error
        strMsg = "Error " & Err.Number & " (" & Err.Description _
            & ") in procedure SaveRecord"
        MsgBox strMsg
    End Select
    Resume ExitHere
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.txtBlock_start.Value) Then
        MsgBox "You must enter a start time!", vbOKOnly, "Start Time"
        Cancel = True
    End If
End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How i can stop the code after opening a dialog box?

From Dev

How can I implement Android Dialog box?

From Dev

How can I remove the box-shadow after clicking away from the input box?

From Dev

How can I confirm script error dialog box into WebBrowser?

From Dev

How can I confirm script error dialog box into WebBrowser?

From Dev

How can I show a JTable in a dialog box in NetBeans?

From Dev

How can I automate the download dialog box in IE using VBA?

From Dev

how can i make my alert dialog box in android

From Dev

How can I disable/falsify .remove() in an if statement?

From Dev

How can I remove the duplicate using statement?

From Dev

How can I create Alert box with a link that is clickable in the alert box or dialog box?

From Dev

What is this small dialog box in the picture? How to remove it?

From Dev

How can I remove the border on a Dialog Window with Dynamic Layout controls?

From Dev

How can I remove the action bar from a dialog

From Dev

How can I use a case statement with a Drop Box? Access Database

From Dev

How can I remove text after clicking?

From Dev

How to trigger a method after closing a dialog box

From Dev

How can i show dialog boxes after each other dynamically?

From Dev

How can I make my trigger button show once I hit the escape key on a dialog box?

From Dev

how can i open my activity similar to alert dialog box if i click any listView Item?

From Dev

How do I make a Modal Dialog Box Auto Open after 2 seconds?

From Java

How do I remove a Vagrant box from global-status, after deleting that box from the filesystem?

From Dev

How can I make an popup box animation after AJAX call?

From Dev

How can I get new changes after restarting Virtual Box?

From Dev

How can I automate Save as dialog box in IE11 using VBA?

From Dev

How can I access my favorites in a Windows 7 file dialog box?

From Dev

How can I gain access to the button of my dialog box that has a partial MVC view?

From Dev

How can i show the change icon dialog box, with a vbscript or a command line?

From Dev

How can I edit the "Save as type:" list in the "Save As" dialog box in Notepad++?

Related Related

  1. 1

    How i can stop the code after opening a dialog box?

  2. 2

    How can I implement Android Dialog box?

  3. 3

    How can I remove the box-shadow after clicking away from the input box?

  4. 4

    How can I confirm script error dialog box into WebBrowser?

  5. 5

    How can I confirm script error dialog box into WebBrowser?

  6. 6

    How can I show a JTable in a dialog box in NetBeans?

  7. 7

    How can I automate the download dialog box in IE using VBA?

  8. 8

    how can i make my alert dialog box in android

  9. 9

    How can I disable/falsify .remove() in an if statement?

  10. 10

    How can I remove the duplicate using statement?

  11. 11

    How can I create Alert box with a link that is clickable in the alert box or dialog box?

  12. 12

    What is this small dialog box in the picture? How to remove it?

  13. 13

    How can I remove the border on a Dialog Window with Dynamic Layout controls?

  14. 14

    How can I remove the action bar from a dialog

  15. 15

    How can I use a case statement with a Drop Box? Access Database

  16. 16

    How can I remove text after clicking?

  17. 17

    How to trigger a method after closing a dialog box

  18. 18

    How can i show dialog boxes after each other dynamically?

  19. 19

    How can I make my trigger button show once I hit the escape key on a dialog box?

  20. 20

    how can i open my activity similar to alert dialog box if i click any listView Item?

  21. 21

    How do I make a Modal Dialog Box Auto Open after 2 seconds?

  22. 22

    How do I remove a Vagrant box from global-status, after deleting that box from the filesystem?

  23. 23

    How can I make an popup box animation after AJAX call?

  24. 24

    How can I get new changes after restarting Virtual Box?

  25. 25

    How can I automate Save as dialog box in IE11 using VBA?

  26. 26

    How can I access my favorites in a Windows 7 file dialog box?

  27. 27

    How can I gain access to the button of my dialog box that has a partial MVC view?

  28. 28

    How can i show the change icon dialog box, with a vbscript or a command line?

  29. 29

    How can I edit the "Save as type:" list in the "Save As" dialog box in Notepad++?

HotTag

Archive