Robert,
You can do this using DOEVENTS somewhere in your processing loop. set a property (e.g. THISFORM.lCancelProcess) to .T. when a the cancel command button is clicked, and check for this value in your processing loop. Example.
FOR nT = 1 TO n
....
....
DOEVENTS
IF THISFORM.lCancelProcess
EXIT
ENDIF
ENDFOR
Depending on the nNumberOfItemsToBeProcessed you may need a mechanism to execute the DOEVENTS less frequently (using a devider), because the doevents takes considerable amounts of time to execute. There is a workarround for the slow doevents written by davind frankenbach (if i'm correct). Yopu may find some more information in the files section.
Walter,
>How do I set up a cancel button to cleanly cancel a process?
>If I have a process button running code in a form, how do I put
>in a cancel button that stays active during the processing so
>that when the cancel button is clicked the processing is stop
>and some cleanup code is run?
>
>Thanks in advance, Robert.