Consulting

Results 1 to 4 of 4

Thread: Solved: userform controls

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    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]

  2. #2
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    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]

  4. #4
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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
  •