>I'm sorry I must be missing something. if that code is at the top of the event how does the code code below it run. There is code in the valid. I do not wish it to run when "cancel" or "close" is clicked. I hope that makes it clearer.
Copy the code into a prg, run it and see ;)
Look at the Valid code again - if LastKey() is
not 27 - i.e., not a Cancel action - the Valid code runs; if it is a Cancel action, the Valid code does not run.
You did say close button, so I also should have included code to allow for the "x" button being clicked. Using this revised valid below and try it then - perhaps it's clearer, too.
Procedure Text1.Valid
If LastKey() = 27 Or thisform.ReleaseType = 1
Return .T.
Else
Return !"-" $ this.Value
EndIf
EndProc
Insanity: Doing the same thing over and over and expecting different results.