Hello All,
I have three text boxes and three command buttons in my userform called "ReqInput". I am trying to perform some action like set enabled properties to False for all command button except first one and set enabled properties to False for all text box except first one and also set focus to first text box. I am using following code
https://onedrive.live.com/?cid=415C...9ADA!13002&parId=415C19A846949ADA!122&o=OneUp
I can use individual command button name to set enabled properties to false and same for text box. But, I am going to handle all these controls using custom event handler and so using for loop.However this gives me error as below. Also I do not see Enabled properties popping up when I type "Ctr.". What is my mistake? Is enabled properties not available when I am using Ctr.
Thanks
Angsuman
I have three text boxes and three command buttons in my userform called "ReqInput". I am trying to perform some action like set enabled properties to False for all command button except first one and set enabled properties to False for all text box except first one and also set focus to first text box. I am using following code
https://onedrive.live.com/?cid=415C...9ADA!13002&parId=415C19A846949ADA!122&o=OneUp
Code:
Dim colReqInputCtr As Collection
Dim clsReqInputObject As clsReqInputClass
Private Sub UserForm_Initialize()
Dim Ctr As Control
Dim CTbx As MSForms.TextBox
Dim i As Long
i = 0
For Each Ctr In ReqInput.Controls
If TypeName(Ctr) = "TextBox" Then
Ctr.Enabled = False
Set clsReqInputObject = New clsReqInputClass
Set clsReqInputObject = Ctr
colReqInputCtr.Add clsReqInputObject
End If
Next
For Each Ctr In ReqInput.Controls
If TypeName(Ctr) = "CommandButton" Then
If Ctr.Caption = "Next" Then
Ctr.Enabled = True
Else
Ctr.Enabled = False
End If
Set clsReqInputObject = New clsReqInputClass
Set clsReqInputObject = Ctr
colReqInputCtr.Add clsReqInputObject
End If
Next
For Each Ctr In ReqInput.Controls
If TypeName(Ctr) = "TextBox" Then
If i = 0 Then
Ctr.Enabled = True
i = i + 1
Else
Ctr.Enabled = False
i = i + 1
End If
End If
Next
End Sub
Thanks
Angsuman
Last edited: