Gracefully cancel a save 
Author Message
 Gracefully cancel a save

I have a data entry form with a 'Save' button that allows the user to save a
new record. There is code tied to the form's Before Update event that checks
to see if the record is complete before saving.  If not, the user is
prompted to save anyway or cancel.

All works well except if the user tries to cancel. The cancel will take
place but an annoying message pops up saying "The setting you entered isn't
valid  for this property" or "The Run Command Action was cancelled."

The actual message depends on the code I use to save the record.  I tried
three methods:
    DoCmd.DoMenuItem.......
    DoCmd. Run Command.acCmdSaveRecord
    If Me.Dirty Then Me.Dirty = False

All of these methods return messages when cancelled.

Does anyone have a suggestion on how I can cancel a save gracefully?

Thanks,
Dave



Sun, 17 Jun 2001 03:00:00 GMT  
 Gracefully cancel a save

Quote:
>All works well except if the user tries to cancel. The cancel will take
>place but an annoying message pops up saying "The setting you entered isn't
>valid  for this property" or "The Run Command Action was cancelled."

[snip]

Quote:
>Does anyone have a suggestion on how I can cancel a save gracefully?

There are several strategies that you may want/need to use in combination,
including trapping errors at in the form's OnError event. (There are some
errors you can't trap there, though, as you no doubt have found out.) Here
is one crude tactic that relies on the SendKeys action. It has helped me in
non-production-quality apps. Ace programmers, please don't flame me for this
;-)

    'test for dirty record
    If Me.Dirty Then
        strM = "You are in the midst of adding/editing this order. "
        strM = strM & "Click OK to proceed without saving changes."
        intR = MsgBox(strM, vbOKCancel, "Order Add/Edit in Progress")
        If intR <> vbOK Then
            GoTo Exiter
        End If
    End If

    'If okay to abort,
    'get rid of that damn pencil
    SendKeys "{ESC}", True
    SendKeys "{ESC}", True

    'close the form or do whatever

Tony Scilipoti
****************
Applications Development Lead
Brigham Surgical Group
Brookline, Massachusetts USA



Sun, 17 Jun 2001 03:00:00 GMT  
 Gracefully cancel a save
Thanks Tony.

I also found an example in Balter's Mastering Access:

    DoCmd.CancelEvent

Dave
-------------------

Quote:

>>All works well except if the user tries to cancel. The cancel will take
>>place but an annoying message pops up saying "The setting you entered
isn't
>>valid  for this property" or "The Run Command Action was cancelled."

>[snip]
>>Does anyone have a suggestion on how I can cancel a save gracefully?

>There are several strategies that you may want/need to use in combination,
>including trapping errors at in the form's OnError event. (There are some
>errors you can't trap there, though, as you no doubt have found out.) Here
>is one crude tactic that relies on the SendKeys action. It has helped me in
>non-production-quality apps. Ace programmers, please don't flame me for
this
>;-)

>    'test for dirty record
>    If Me.Dirty Then
>        strM = "You are in the midst of adding/editing this order. "
>        strM = strM & "Click OK to proceed without saving changes."
>        intR = MsgBox(strM, vbOKCancel, "Order Add/Edit in Progress")
>        If intR <> vbOK Then
>            GoTo Exiter
>        End If
>    End If

>    'If okay to abort,
>    'get rid of that damn pencil
>    SendKeys "{ESC}", True
>    SendKeys "{ESC}", True

>    'close the form or do whatever

>Tony Scilipoti
>****************
>Applications Development Lead
>Brigham Surgical Group
>Brookline, Massachusetts USA




Sun, 17 Jun 2001 03:00:00 GMT  
 Gracefully cancel a save
There's also docmd.runcommand acCmdUndo.



Quote:
> I have a data entry form with a 'Save' button that allows the user to
save a
> new record. There is code tied to the form's Before Update event that
checks
> to see if the record is complete before saving.  If not, the user is
> prompted to save anyway or cancel.

> All works well except if the user tries to cancel. The cancel will take
> place but an annoying message pops up saying "The setting you entered
isn't
> valid  for this property" or "The Run Command Action was cancelled."

> The actual message depends on the code I use to save the record.  I tried
> three methods:
>     DoCmd.DoMenuItem.......
>     DoCmd. Run Command.acCmdSaveRecord
>     If Me.Dirty Then Me.Dirty = False

> All of these methods return messages when cancelled.

> Does anyone have a suggestion on how I can cancel a save gracefully?

> Thanks,
> Dave



Sun, 17 Jun 2001 03:00:00 GMT  
 Gracefully cancel a save
Not the right way, but it will work....

Example below is the code that is "automatically" placed in a close button.
You can simply replace the
"On Error GoTo Err_cmdExit_Click" with "On Error Resume Next".  This would
allow processing;
------------------------------------------------------
On Error GoTo Err_cmdExit_Click

WarnOff  'added as part of functions noted below
DoCmd.Close
WarnOn  'added as part of functions noted below

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.DESCRIPTION
Resume Exit_cmdExit_Click
------------------------------------------------------

better yet, create these two functions:
------------------------------------------------------
Function WarnOff()
' Turn Comfirmations Off
Application.SetOption "Confirm Action Queries", False
Application.SetOption "Confirm Document Deletions", False
Application.SetOption "Confirm Record Changes", False
DoCmd.SetWarnings False
End Function
------------------------------------------------------
Function WarnOn()
' Turn Comfirmations On
Application.SetOption "Confirm Action Queries", True
Application.SetOption "Confirm Document Deletions", True
Application.SetOption "Confirm Record Changes", True
DoCmd.SetWarnings True
End Function

------------------------------------------------------

This will "quiet" the messages you see, but not true errors.

Regards,

Todd



Sun, 17 Jun 2001 03:00:00 GMT  
 Gracefully cancel a save
Dave,

Looks like there are lots of alternatives for this based on all the posts.  I
had the same annoying warning box, and below is the code I added.

  On Error GoTo Err_cmdDelete_Click

..your code to validate user entries..

Exit_cmdDelete_Click:
    Exit Sub

Err_cmdDelete_Click:
    If Not Err.Number = 2501 Then       'Err 2501 is raised from cancel of
DoCmd action.
        MsgBox Err.Description
    End If

    Resume Exit_cmdDelete_Click

End Sub

David

- - - - - - - -

Quote:

>I have a data entry form with a 'Save' button that allows the user to save a
>new record. There is code tied to the form's Before Update event that checks
>to see if the record is complete before saving.  If not, the user is
>prompted to save anyway or cancel.

>All works well except if the user tries to cancel. The cancel will take
>place but an annoying message pops up saying "The setting you entered isn't
>valid  for this property" or "The Run Command Action was cancelled."

>The actual message depends on the code I use to save the record.  I tried
>three methods:
>    DoCmd.DoMenuItem.......
>    DoCmd. Run Command.acCmdSaveRecord
>    If Me.Dirty Then Me.Dirty = False

>All of these methods return messages when cancelled.

>Does anyone have a suggestion on how I can cancel a save gracefully?

>Thanks,
>Dave

David


Mon, 18 Jun 2001 03:00:00 GMT  
 Gracefully cancel a save
I find it easier to type the following.  Works well, less keystrokes... <g>

me.undo

Gary :)

Quote:

>There's also docmd.runcommand acCmdUndo.



>> I have a data entry form with a 'Save' button that allows the user to
>save a
>> new record. There is code tied to the form's Before Update event that
>checks
>> to see if the record is complete before saving.  If not, the user is
>> prompted to save anyway or cancel.



Tue, 19 Jun 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. using VBA I need to determine is the user canceled or saved my form

2. cancel save of custom form

3. using VBA I need to determine is the user canceled or saved my form

4. How i can cancel the save operation?

5. Cancel Save

6. Newbie q: Save Internet (HTML) file to local/Cancel ShowPrinter

7. Save & Cancel button for DataGrid

8. Detect Runtime Installation - Gracefully Exit if not?

9. exit loop gracefully??

10. gracefully closing apps from within vb

11. Gracefully exiting an ActiveX Document!

12. HOWTO: Gracefully Free Object Memory

 

 
Powered by phpBB® Forum Software