PDA

View Full Version : Solved: userform controls



gibbo1715
10-09-2005, 01:53 AM
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??

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

gibbo1715
10-09-2005, 02:05 AM
Ok silly mistake if i change

If Left(ctrl.Name, 9) = "Text" Then


as follows

If Left(ctrl.Name, 4) = "Text" Then


works fine for me

Thanks for looking

Gibbo

Norie
10-09-2005, 03:27 AM
Gibbo

There are actually a couple of other ways to check if a control is a textbox.

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

gibbo1715
10-09-2005, 04:57 AM
thanks norie,

i ll remember those for future use

Gibbo