I have a form w/ a textbox and Cancel button on it. When I click on the cancel button it doesn't even get to the cancel.click event until AFTER it has done the validating. As far as the original validation issue, I started a new project (VB2005) and tried your approach It works except that pressing the Esc key still causes the validation event to fire. According to the documentation: "The cancel button for a form is the button control that is clicked whenever the user presses the ESC key." Which says to me the behavior s/b the same! Validating If Not mbln Cancel Then Dim dte Date As Date Time If Date Time. Also note that the "trick" to closing the form is not keeping a seperate "canceling" flag, but to put "e.cancel=False" in the forms closing event.
Then in the btn Cancel_click event, either set a module level variable like m Canceling to True and then in the validating event ... I've been fighting the same problem for some time now. I think that the only way to do this is to grab the mouse coordinates in the validating event, do a Window From Point API call, then compare the returned HWND to the Cancel Button's Handle. Close() End Sub Private Sub Text Box1_Validating(By Val sender As Object, By Val e As System. When you click on the button the validating event fires. If the handle matched then immediately exit the Validating event without setting e. -- Al Reid I had tried all of that, *BUT*, I had neglected to set the button's Causes Validation to False. I just don't know what key code combination could direct focus to a text box control that should never receive focus since the Tab Stop property is false and there is no other code that sets focus to the textbox. Also in the docs on Key Down there is a mention of "Is Input Key" which I will have to look into. However, after I removed the "canceling" flag and added the "e.cancel=False" to the form's Form Closing event, I once again see the validation when clicking on the cancel button, but the form then closes after displaying the validation error. -- Al Reid "Terry" Hi Al, Don't know if you have been following the thread I started about the escape key "bug", but if you search this community for "Cancel Button vs Escape Key", you can see the result including the work around for the escape key. Close())å Form1_Load text Box1_Enter Form1_Activated text Box1_Leave button3_Enter button3_Click text Box1_Validating text Box1_Validated Form1_Closing Form1_Closed Form1_Deactivate text Box1å Form1_Load text Box1_Enter Form1_Activated text Box1_Validating # Validatingȯ롣 text Box1_Validated Form1_Deactivate ޤȤȡ եΡĤץܥ̵ˤ: . Validating ȯʤ button2_Enter button2_Click text Box1button3(Causes Validation=false & this. B_Enter 褦ϡ 2.ͤå 3.ͤ # Ϥå硢2.0-9ޤǤʸå # ʳʸޤޤƤ硢եư # 3."000123"ʤɤ"123"Ȥ褦ʴ Ȥեˤϡ֥ץܥ䡢ե౦ܥ ˤϡץफClose()ǥեĤ륱롣 ξˡValidating¹ԤԹ礬 ΤˡCauses ValidationΤClose()ȼ˲ 뾮ٹɬפǤ롣 ʤɤʤɤΤȤˤĤĴ롣 text Box1˥եƤƤưԤäȤ Validating٥Ȥȯ̵ͭĴ text Box1button1(Causes Validation=true)å Form1_Load text Box1_Enter Form1_Activated text Box1_Leave text Box1_Validating # Validatingȯ롣 text Box1_Validated button1_Enter button1_Click text Box1button2(Causes Validation=false)å Form1_Load text Box1_Enter Form1_Activated text Box1_Leave # Causes Validation=false ΥܥåΤ # text Box1.Text Box1の値を判定するならは Sub test() Dim n As Integer If Integer. Text, n) Then Select Case n Case 0 To 9, 30 To 300 Message Box.