Validating event of textbox
All you need to see and reproduce in your own code in order to force validation is to add the 'e.
Cancel = true' instruction at the right place of your own validating method.
Any attempt to do so through a Form Closing handler will not work because it is then too late once execution reaches such handler.
However, the click of the "X" button can be captured promptly via overriding the Wnd Proc() method and testing for a 'm. When that condition is true, the previously introduced 'Auto Validate = Auto Validate. Error Text = "" End If End Sub I came here in search of a simple method to cause a form to close when a Validating event handler raises an exception, reports it, and needs to force the form to close.
That is not so for the Form Closing events that will all execute after validating events.
That is why that validation cannot be disabled from any of these Form Closing events.
Active Control property to the current form, focus events occur in the following order: I'd suggest using the Leave because I assume you aren't validating the value, but formatting it.
I'm a bit confused, as far as I remember the Textbox used to launch the Validating event when the used pushed the Enter key after entering the desired text but this is not happening now.The problem is, when I click the X button on the right top corner of the form, I don't want the validation to be fired because I am closing the form anyway. A control event list is accessed by clicking this control's property sheet’s event (lightning looking) toolbar button.You can then enter the code in the automatically generated handler with a name combining both the name of the control and '_Validating'.The part of this handler where something is established as invalid can force valid entries by adding the 'e. For such validating method examples, See 'txt IPAddress_Validating()' and 'txt Mask Bits_Validating()' code below.Do not get distracted by the complete validation mechanism of these specific examples.