-
Solved: userform controls
I am trying to use the code below to establish if a textbox on a userform has anything in it, but when i click on the button nothing happens at all, even when there is content in a TextBox
Anyone got any ideas please??
[VBA]Private Sub CommandButton1_Click()
Dim ctrl As MSForms.Control
For Each ctrl In UserForm1.Controls
If Left(ctrl.Name, 9) = "Text" Then
If ctrl.Value <> "" Then
MsgBox ctrl.Name
End If
End If
Next
End Sub [/VBA]
-
Ok silly mistake if i change
[VBA]If Left(ctrl.Name, 9) = "Text" Then
[/VBA]
as follows
[VBA]If Left(ctrl.Name, 4) = "Text" Then
[/VBA]
works fine for me
Thanks for looking
Gibbo
-
Gibbo
There are actually a couple of other ways to check if a control is a textbox.
[vba]
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
MsgBox ctl.Name
End If
If TypeName(ctl) = "TextBox" Then
MsgBox ctl.Name
End If
Next ctl[/vba]
-
thanks norie,
i ll remember those for future use
Gibbo
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