Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Select text on enter field/control (XP)

    I searched the online help, as well as searching here for a solution. I had no luck and would like to ask the group the following:

    Is there a way to programmatically select the text in a control on a form upon entry? In 90% of the controls on the forms used, it is preferred that the text NOT be selected (which is easily handled in the Tools:Options:Keyboard:"Behavior entering field"). It would be very nice to be able to select all the data upon entry instead of having the user use the mouse to select it.

    Thanks in advance for your ideas.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Select text on enter field/control (XP)

    It's fairly easy to select text in a control by using the SHIFT, CTRL and ARROW keys from the keyboard - so users can be trained to do that. But you can also do that same thing by manipulating SelLength for a control in VBA - first you have to determine the insertion point, and then the length of the text. Do a search in VBA help for SelLength.
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Select text on enter field/control (XP)

    Use the On Enter event of the control to select the entire contents, for example:

    Private Sub LastName_Enter()
    Me.LastName.SelStart = 0
    Me.LastName.SelLength = Len(Me.LastName.Text)
    End Sub

    Note that this only works if the user enters the field using tab or enter (or a shortcut key), not if the user clicks in the field. This is the same as when you set "Behavior entering field" to "Entire field".

  4. #4
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Select text on enter field/control (XP)

    Wendell and Hans,

    THANKS! Outstanding! I appreciate your help.

    Ken

Posting Permissions

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