|
-
Nov 22nd, 2000, 02:25 PM
#1
Thread Starter
Addicted Member
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
-
Nov 22nd, 2000, 02:28 PM
#2
Hyperactive Member
Very close!
This should work
Private Sub Command1_Click()
For Each TextBox In Me
TextBox.Enabled = Fasle
Next
End Sub
Matt 
-
Nov 22nd, 2000, 02:47 PM
#3
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:
Code:
Dim ctl As Control
For Each ctl In Me.Controls
If IsTextBox(ctl) Then
ctl.Enabled = False
End If
Next
And the IsTextBox() code would read:
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
This code has been tested and does work.
Paul
-
Nov 22nd, 2000, 03:44 PM
#4
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
-
Nov 22nd, 2000, 03:56 PM
#5
Like I said Megatron, I knew there was a better way, I just couldn't remember/find it! Thanks for the insight.
Paul
-
Nov 22nd, 2000, 03:57 PM
#6
Thread Starter
Addicted Member
thanks for all the comments..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|