* Loop code checking for the cancel button lnCnt = 1 SCAN blah blah IF MOD(lnCnt,100) = 0 DOEVENTS ENDIF lnCnt = lnCnt + 1 ENDSCANNow you would need to do something in the Cancel button that the code above could sense. I usually set the Cancel property of the button to .T. and add code like this.
* Loop code checking for the cancel button lnCnt = 1 llAbort = .F. SCAN blah blah IF MOD(lnCnt,100) = 0 DOEVENTS IF LastKey() = 27 && Escape llAbort = .T. EXIT ENDIF ENDIF lnCnt = lnCnt + 1 ENDSCAN IF llAbort * Do what is needed to abort the process gracefully ENDIF