Cancel

save
WHAT CAN CAN BE THE CODE FOR CANCEL BUTTON?

You could add

Msgbox “Why do you click on the cancel button?”

1 Like

We can help you with the code you have written. But we can’t write your code for you. Please have a more thorough look at the examples and the docs. Then come back with a more detailed question.

I’ve already told you the answer to that question in another thread about this very same process.

Since you’re canceling the “Save” task, the Cancel button code just needs to close the window. In the button’s Action event:

Window1.close

Where Window1 is the name of the Save dialog.

No, it is a “do you want to save the changes” dialog. Cancel should cancel the close, leaving the window open and unchanged. Return True form the CancelClose event.

1 Like

of course. need more coffee.

This looks like the kind of alert one gets when one has attempted to close the window holding the document or has attempted to quit the program.

Save: Saves the document and closes/quits.
Don’t Save: Does not save the document and closes/quits.
Cancel: Does not save the document and does NOT close/quit.

:slight_smile:

not working

CODE IS

Var MesDia As New MessageDialog
Var MesDiaButton As MessageDialogButton

MesDia.Icon = MessageDialog.GraphicCaution

MesDia.ActionButton.Caption = "Save"
MesDia.CancelButton.Visible = True 

MesDia.AlternateActionButton.Visible = True
MesDia.AlternateActionButton.Caption = "Don't Save"

MesDia.Message = "Do you want to save changes to this document before closing?"

MesDia.Explanation = "If you don't save, your changes will be lost. "


MesDiaButton = MesDia.ShowModal

Select Case MesDiaButton 
  
Case MesDia.ActionButton
  SaveDocument()
  
Case MesDia.AlternateActionButton
  
Case MesDia.CancelButton
  MesDia.close
  
End Select
Select Case MesDiaButton 
  
Case MesDia.ActionButton
  SaveDocument()
  // And close!
  
Case MesDia.AlternateActionButton
  MesDia.close // Close here w/o saving!
  
Case MesDia.CancelButton
  // Here do nothing.
End Select

MessageDialog sucks, dont use it. It is not a native windows dialog, just a regular window that does not comply with the windows guidelines. Also, uses a lot of code for what it does.


'This code asumes you are in the CancelClose Event

Var Result As Integer
Result = MsgBox("Do you want to save changes to this document before closing?" + EndOfLine + EndOfLine + "If you don't save, your changes will be lost.", 51)

Select Case Result
Case 6 
  // user pressed Yes
  'SaveChanges()
  Return False
Case 7
  // user pressed No
  'Dont save, just let it close
  Return False
Case 2
  // user pressed Cancel
  'Dont save, and dont close
  
  Return True
End Select

Edit: Fixed Case for Cancel

You have “Case 6” twice.

1 Like

The code goes in the CancelClose event NOT the Close event.