How would i make all the textboxes in my form become disabled?? Am I on the right track?? thank you
Private Sub Command1_Click()
Dim text As TextBox
For Each text In ???
text.Enabled = False
Next
End Sub
Printable View
How would i make all the textboxes in my form become disabled?? Am I on the right track?? thank you
Private Sub Command1_Click()
Dim text As TextBox
For Each text In ???
text.Enabled = False
Next
End Sub
This should work
Private Sub Command1_Click()
For Each TextBox In Me
TextBox.Enabled = Fasle
Next
End Sub
There are probably better ways to do it, but one way to do it would be to loop through the forms controls collection examing each control to see if it's a textbox (I use a custom function here based on the textbox's MultiLine property - there's gotta be a better way but I couldn't find it in my limited search) and disabling it if it is a textbox. I'm checking the MultiLine property to see if a control is a textbox as I don't think any other controls have this property.
The code would look something like this for the loop:
And the IsTextBox() code would read:Code:Dim ctl As Control
For Each ctl In Me.Controls
If IsTextBox(ctl) Then
ctl.Enabled = False
End If
Next
This code has been tested and does work.Code:Public Function IsTextBox(ctl As Control) As Boolean
Dim blnReturn As Boolean
blnReturn = False ' Default value.
On Error GoTo Error_Handler
blnReturn = (ctl.MultiLine = ctl.MultiLine)
Error_Handler:
IsTextBox = blnReturn
End Function
Paul
Why do you need that function? It's much easier to use the TypeOf statement.
Code:Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.Enabled = False
End If
Next ctl
Like I said Megatron, I knew there was a better way, I just couldn't remember/find it! Thanks for the insight.
Paul
thanks for all the comments..