* the control oFirstControl is a control on the form thisform.oFirstControl.SetFocus() NODEFAULTI have code in my base control classes so that the controls update a pair of Form properties tracking Form object refs as they receive focus; I use these properties to determine the control that last received control within the Form:
* In the GotFocus of each base class IF TYPE('thisform.oLastGotFocus') = 'U' thisform.AddProperty('oLastGotFocus', NULL) ENDIF IF TYPE('thisform.oPriorGotFocus') = 'U' thisform.AddProperty('oPriorGotFocus', NULL) ENDIF thisform.oPriorGotFocus = thisform.oLastGotFocus thisform.oLastGotFocus = this * In the Release of the base Form class; need to release the object refs * so that the Controls can be fully released without leaving any dangling * object refs to prevent Form deinstantiation IF TYPE('thisform.oPriorGotFocus') # 'U' thisform.oPriorGotFocus = NULL ENDIF IF TYPE('thisform.oLastGotFocus') # 'U' thisform.oLastGotFocus = NULL ENDIFYou can expand on these relatively easily, and change the LostFocus code in the pseudo-modal form to return control to the previous control by:
NODEFAULT WITH thisform IF TYPE('.oLastGotFocus') = 'O' AND ! ISNULL(.oLastGotFocus) LOCAL oGotFocusRef oGotFocusRef = .oLastGotFocus && Save Last ref to var and move .oLastGotFocus = .oPriorGotFocus && Prior to Last to preserve the oGotFocusRef.SetFocus() && Prior when Last GotFocus() fired ELSE * No Last Control available so use first enabled and visible LOCAL nCtrlCnt FOR nCtrlCnt = 1 TO .ControlCount IF .controls(nCtrlCnt).Enabled AND .controls(nCtrlCnt).Visible .controls(nCtrlCnt).SetFocus() ENDIF ENDFOR .Show() && I can't figure out what to do, so just Show the Form ENDIF ENDWITH