This is my first post, so I’m also saying hi to the community. Hai.
I have a problem with a form I am working on. Namely, the user has to fill in the form with data and then select OK or Cancel, one of which is supposed to save the data and the other one is supposed to discard it. No the datasource of the form contains two override methods (ValidateWrite and Write) and the OK and Cancel buttons both have overriden Clicked methods.
whenever I or an user presses OK or Cancel the program executes validateWrite before the Clicked method. Unfortunately, if validateWrite returns true, the data is written into the database, which is a huge problem if for example the user presses cancel.
Has anyone got an idea to overcome this problem?
Setting the property “SaveRecord = No” for the Cancel button will do the job. Record saving process initiated by an event “leaveRecord()” (because you leave the record as you press the button) won’t be called and therefore no validations will be done and user won’t get unnecesary warnings if he is not saving the record anyways.
thank you Janis.
Although I made a (half-assed if you will) solution to the problem. Namely I used the MouseDown override methods, since they run before the validateWrite method and thus I could direct the program in the way I wanted.
Although if I had seen your post earlier, I would’ve used your approach
just to add up - I would suggest that you do use the SaveRecord=No approach for this reason. “MouseDown” relates to mouse events only (i.e., if user clicks on a button with mouse), but there is also a chance to navigate to the “Cancel” button in the current form with Tab button on keyboard by iterating through controls, and when after few Tab pushes the “Cancel” button is highlighted, user can press Space button on keyboard and - VOILA, he basically clicks on that button without using mouse. You may think of this as of a strange scenario, but for example I do it a lot, I sometimes don’t use mouse in some simple forms (like dialogs)… and I know I am not the only one. And if I would be a user using your AX system, your code wouldn’t work for me and the record would be saved
If you adore the code you have written in MouseDown, you may leave it there for the time being, but still I would advise you to set this one single SaveRecord parameter of the Cancel button to “NO”. It does not hurt, but helps a lot.