Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleEnable or disable all controls on a form
Keywordscontrol, enable, disable
CategoriesTips and Tricks, Controls
 
Loop through the form's Controls collection setting each control's Enabled property to True or False.

Note that some controls do not have an Enabled property (for example, Shape controls) so the program must use an On Error statement to protect itself.

Note also that you can disable the entire form by setting its Enabled property to False. Unfortunately that disables everything on the form including the form's system menus so the user cannot close it. The form's controls also look like they are enabled even though the user cannot interact with them.

Similarly you can disable the controls inside a Frame by setting the Frame's Enabled property to False but the controls still look enabled.

 
' Enable or disable the form's controls.
Private Sub EnableControls(ByVal frm As Form, ByVal _
    enabled_state As Boolean)
Dim ctl As Control

    ' Examine every control.
    For Each ctl In frm.Controls
        ' Don't disable the form's CheckBox or the user
        ' won't be able to reenable it.
        If Not (ctl Is chkControlsEnabled) Then
            On Error Resume Next
            ctl.Enabled = enabled_state
            On Error GoTo 0
        End If
    Next ctl
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated