Article ID: 132071
Article Last Modified on 1/19/2007
Name: MyButton
Caption: Lock All Textboxes
Sub MyButton_Click ()
Dim i As Integer
Static status As Integer ' Use variable as True/False flag.
' Toggle the button's Caption property.
If status = False Then
MyButton.caption = "Unlock All Textboxes"
Else
MyButton.caption = "Lock All Textboxes"
End If
' Cycle through the form's controls,
' testing for text and combo boxes,
' and set each control's Locked/Enabled properties.
For i = 0 To Me.count - 1
If TypeOf Me(i) Is textbox Then
Me(i).locked = status: Me(i).enabled = status
ElseIf TypeOf Me(i) Is combobox Then
Me(i).locked = status: Me(i).enabled = status
End If
Next
' Toggle the flag.
status = Not status
End Sub
Additional query words: report loop object enumerate collection
Keywords: kbhowto kbprogramming kbusage KB132071