Can we use the SELTEXT property outside textbox control?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Janu Satish
    New Member
    • Dec 2010
    • 6

    Can we use the SELTEXT property outside textbox control?

    In my form i need to select the value in my textbox as soon as i click a button. But when i gave the txtname.seltext inside the button click event im receiving an error as 'misuse of the property'...
    Thanks in advance....
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    In order to select Text in a Text Box via the Click() Event of a Command Button:
    1. Make sure the Text Box does not contain a NULL Value, if it does simply Exit the Click() Event in one form or another. (Line 5).
    2. Set Focus to the Text Box. (Line 6).
    3. Set the SelLength of the Text Box equal to the Length of the Value in the Text Box. This will select the Text in its entirety. (Line 7).
    4. To retrieve the Selected Text, use the SelText Property. (Line 8).
      Code:
      Private Sub Command120_Click()
      'Substitute your Text Box Name for Text2
      Set txt = Me![Text2]
      
        If Not IsNull(txt) Then
          txt.SetFocus
          txt.SelLength = Len(txt.Value)
            MsgBox "The Text Selected is " & txt.SelText
        End If
      End Sub

    Comment

    • Janu Satish
      New Member
      • Dec 2010
      • 6

      #3
      Thanks... It works:)

      Comment

      Working...