>>David,
>>
>>I tried your suggestion for breaking out of an infinite loop. I must still be doing something wrong. Can you see anything wrong with this picture?
>>
>>I took one button on my form and named it cmdCloseWindow and set its Cancel property to .T. as you suggested. You mentioned that pressing the button would return a 27 which looks like an ESC key to me. But I believe I also SET ESCAPE OFF in the form Load procedure. Any ideas why it's not working to break out of the loop? That's all that is wrong with my form. Here's my code:
>>
>>DO WHILE .T.
>> SCAN
>> DOEVENTS()
>> IF LASTKEY() = 27
>> EXIT
>> ENDIF
>>... my main code is here
>> ENDSCAN
>
>You need TWO exits - one from the SCAN, and one from the DO WHILE, or you need a way to terminate the DO WHILE, like:
>
>
lExit = .F.
>DO WHILE ! lExit
> GO TOP
> SCAN WHILE ! lExit
> * do what you want
> DOEVENTS()
> lExit = (LASTKEY() = 27)
> ENDSCAN
>ENDDO
>
BTW, there's a semi-subtle bug here - you'll never be able to exit with the code above unless there's at least one record in the table; if the table is empty, the code within the SCAN loop never executes. So checking LASTKEY() outside the SCAN is also needed...
>>ENDDO