Home > OS >  Selecting the whole of a textbox once a option is clicked in a dropdown list
Selecting the whole of a textbox once a option is clicked in a dropdown list

Time:08-13

I am trying to make a form for people to fill out. There is dropdown list that people click on to choose options. One of the options is "Other" which will activate a textbox to be able to free write what they want in. To make it easier and more obvious as to where they need to write it in I would like the text that is originally in the textbox to be selected so they do not have select all the text in there and then delete it.

I have some code that I thought would work but does not seem to work all the time. Once I have done the code it will work for a couple of time but then not work.

The code that I have is:

Private Sub ComboBox1_Change()
If ComboBox1.Value = "Other" Then
   MsgBox "Please Specify below"
   TextBox1.Enabled = True
   TextBox1.Select
ElseIf ComboBox1.Value <> "Other" Then
   TextBox1.Enabled = False
   TextBox1.Value = "Please Specify"
End If
End Sub

Any help would be much appreciated. Thanks!

CodePudding user response:

Should work with ActiveX Controls now ;)

Private Sub ComboBox1_Change()
If ComboBox1.Text = "Other" Then
    MsgBox "Please Specify below"
    With TextBox1
        .Enabled = True
        .Select
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
Else
   TextBox1.Enabled = False
   TextBox1.Text = "Please Specify"
End If
End Sub

It selects TextBox1 and then selects as many characters there are in TextBox1.Text

  • Related