Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: First Control in a ReadOnly subform retains focus

Author(s)
Dev Ashish

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  *****

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer