Visual Basic 6 – How to Disable All controls in a form?

Send Us a Sign! (Contact Us!)
--> (Word) --> (PDF) --> (Epub) --> (Text)
--> (XML) --> (OpenOffice) --> (XPS)

SCENARIO

How to disable some control in form?

For example, disable all command button and all textbox in a form???

SOLUTION (1st Method)

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is CommandButton Then
ctrl.Enabled = False
End If
Next

Function Version (by Heelpbook Staff)

Public Function disena(switch As Integer)
If switch = 1 Then
enable = True
Else
enable = False
End If
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is CommandButton Then
ctrl.Enabled = enable
End If
Next
End Function

SOLUTION (2nd Method)

To disable all of them you can simply disable entire form - until your main logic is done user won't be able to close the form:

Private Sub Command1_Click()
'disable form
Me.Enabled = False
'do your main stuff here
'reset the form
Me.Enabled = True
End Sub

SOURCE

LINK (vbforums.com)

LANGUAGE
ENGLISH