I've done this a lot, even with ActiveX controls on the form, and I've never had to setfocus before it would work. One thing that may be getting in your way is any validation going on. I bracket validation code with IF NOT LASTKEY() = 27 so that Escape will bypass the validation and just exit the form.
>Problem was fixed by adding Thisform.PageFrame1.Page1.Command2.SetFocus() in Thisform.Init().
>
>Maybe problem was created because there is an OleControl in page1?
>
>Thanks,
>
>Alex
>
>>Hi,
>>
>>A form has a pageframe an in a page a command button for which I set Cancel .T., wishing it to respond to escape key. However, the escape key does not cause the commandbutton click to fire. Next I added code in Thisform.KeyPress and Thisform.KeyPreview = .T., but still no response to Escape key.
>>
>>What am doing wrong?
>>
>>Thanks,
>>
>>Alex