>In textbox valid event i put this code that check if the code already exist
>
>if seek(this.value, 'Customer1')
> return .f.
>endif
>
>I want that when user press cancel button this valid event shouldn't fire.
One way to do it is to activate a flag when cancel is pressed, such as ThisForm.lQuiting=.T. So, you could use a verification here to detect that and don't proceed if it is in effect.
IF ThisForm.lQuiting
RETURN
ENDIF
if seek(this.value, 'Customer1')
return .f.
endif
There might be better ways to do it. This is just one approach.