Results 1 to 7 of 7

Thread: Tab question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80
    Uhm, this is probably a silly question but....how would I make so that when a textbox gets the focus; if there is any text, it gets highlighted by the cursor. Thanks in advance.

    -Jack Vinitsky

  2. #2
    Junior Member
    Join Date
    Jul 2000
    Location
    Mexico
    Posts
    24

    Smile

    I think its something like this:

    Text1.selstart = 0
    Text1.sellenght = len(text1.text)

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Code:
    Private Sub txtName_GotFocus()
        txtName.SelStart = 0
        txtName.SelLength = Len(txtName.Text)
    End Sub
    Iain, thats with an i by the way!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80
    Thanks fot the help. Do I have to paste that in the got_focus event of each of text box on my form or is there another place I can put it so that it affects all of them?

    -Jack Vinitsky

  5. #5
    Guest
    You would probably have to put that in all of them, unless you want to put it in a function instead.


  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80
    Thanks for all the help.

    -Jack Vinitsky

  7. #7
    Addicted Member P.S.W.'s Avatar
    Join Date
    Aug 2000
    Posts
    146
    Actually, I've tackled this same problem you have, and if you have a lot of textboxes & multiple forms, here is one solution:

    1. Array all the textboxes
    2. Create the following sub: (if you put this in a module it will work for all your forms)

    Public Sub Highlight()
    'This highlights the text in the active textbox
    With Screen.ActiveForm
    If (TypeOf .ActiveControl Is TextBox) Then
    .ActiveControl.SelStart = 0
    .ActiveControl.SelLength = Len(.ActiveControl)
    End If
    End With
    End Sub

    3. Then in the GotFocus Event:

    Textbox_GotFocus(Index as Integer)
    Call Highlight
    End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width