>I had a similar problem recently and I found that if you are closing the form using the "X", there is no way to prevent the valid code from running in the last object that had the focus. However, if you are releasing the form by clicking on a command button that is located on the form you can prevent the valid code from running by creating a form property, such as lIsExiting, and setting it to .T. in the gotfocus event of the command button. Then place validation code in the valid event of the object that prevents the code from running if thisform.lIsExiting = .T.
>
>Unfortunately, I couldn't find a way to access the gotfocus event of the "X" button so I had to set the form's closable property to .F. and remove the user's ability to close the form with the "X". It's not the best solution, but it worked.
Instead of Valid() event, I could put the code in a method and call that method when the keypress of the control textbox is a carriage return.