ðHgeocities.com/Heartland/Pond/4805/Form2.htmgeocities.com/Heartland/Pond/4805/Form2.htm.delayedxÄPÔJÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿȰ&ì\OKtext/html€çh\ÿÿÿÿb‰.HSun, 20 Jan 2002 13:01:37 GMTJMozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)en, *ÄPÔJ\ First Control in a ReadOnly subform retains focus

---Posted by Dev Ashish---


Forms: First Control in a ReadOnly subform retains focus


In order to visually inform the user that the subform is read only,  many developers set the Locked property of the Subform or the controls and the BackColor property of the controls to True.  But whenever the subform loses focus, the first control remains selected which changes it's BackColor to Normal.  This can be annoying.

To fix this behavior:

  1. Create another dummy textbox (txtDummy) on the subform.

  2. Set it's Width and Height properties to zero.

  3. Set it's Locked property to True. 

  4. Move this textbox to the very top of the TabOrder under View | Tab Order. 

  5. Include this code in the parent form in the subform's Exit event.

'   ***** Code Start *****

Private Sub SubFormName_Exit(Cancel As Integer)

   On Error Resume Next

   Me.SubFormName.Form.txtDummy.SetFocus

End Sub

'   ***** Code End  *****