Maybe I am not using the correct search terms, but I am unable to find an answer to this design issue. I have a userform (several in fact) that have a multicolumn list for records related to that form. I have a good amount of validation that I run on some fields utilizing the Cancel function within the BeforeUpdate or Exit event of the textbox. I do this to provide immediate feedback and show detailed error messages - not letting them out of the field until the error is resolved - rather than wait for the full record save to do the error checking. But this design approach is causing issues.
Here is a specific scenario. Textbox1 has a date in it, which I check for bad date format and a few other things on the BeforeUpdate event. The user clicks on the first record in the list, which loads the saved date into Textbox1. No issues. Now the user deletes the entry in Textbox1 and decides to close the form without exiting the field. The user's changes are irrelevant to me as they have not been saved and will not be saved with closing the form. However Excel runs the BeforeUpdate event on Textbox1 immediately upon the close button being clicked. I get a Type Mismatch error because part of my validation is doing math on that date, which it now see as empty. And it does this before it even gets to the close function. It may help for me to note that I have the title bar and "X" hidden on these forms and am controlling closing of the form with my own button. But the same behavior exists with the Excel close "X".
Any ideas on how I can design around this? Am I going to have to move all the data validation to my Save function and skip the BeforeUpdate and Exit events? I am hoping I am just focusing too narrowly and not seeing a better way.
Here is a specific scenario. Textbox1 has a date in it, which I check for bad date format and a few other things on the BeforeUpdate event. The user clicks on the first record in the list, which loads the saved date into Textbox1. No issues. Now the user deletes the entry in Textbox1 and decides to close the form without exiting the field. The user's changes are irrelevant to me as they have not been saved and will not be saved with closing the form. However Excel runs the BeforeUpdate event on Textbox1 immediately upon the close button being clicked. I get a Type Mismatch error because part of my validation is doing math on that date, which it now see as empty. And it does this before it even gets to the close function. It may help for me to note that I have the title bar and "X" hidden on these forms and am controlling closing of the form with my own button. But the same behavior exists with the Excel close "X".
Any ideas on how I can design around this? Am I going to have to move all the data validation to my Save function and skip the BeforeUpdate and Exit events? I am hoping I am just focusing too narrowly and not seeing a better way.