Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Apr 2006
    Location
    California
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Seltext (Access 2007)

    I have a command button who's OnClick event copies the text from TextBoxA and appends to TextBoxB. I would like to be able to select only part of the text in TextBoxA rather than the whole contents. I have not been able to get the timing down using SelText. The required TextBoxA.SelText in my command button OnClick event drops what had been selected and the necessary intermediate step is eluding me.

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

    Re: Seltext (Access 2007)

    The problem is - as you noted - that the selection is lost the moment you exit the text box.

    One workaround is to use a toolbar button instead of a command button on the form itself. Clicking the toolbar button doesn't make the text box lose focus, so the selection is still valid.

    Another option is to store the selected text in a variable when the user exits the text box.
    - Put the following declaration at the top of the form's module (below Option Compare Database and Option Explicit, but above all Subs and Functions):
    <code>
    Private strText As String
    </code>
    - Create an On Exit event procedure for TextBoxA:
    <code>
    Private Sub TextBoxA_Exit(Cancel As Integer)
    With Me.TextBoxA
    strText = Mid(.Text, .SelStart + 1, .SelLength)
    End With
    End Sub
    </code>
    Use code like this in the On Click event of the command button:
    <code>
    Me.TextBoxB = Me.TextBoxA & strText
    </code>
    You must, of course, use the actual names of the text boxes.

  3. #3
    Star Lounger
    Join Date
    Apr 2006
    Location
    California
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Seltext (Access 2007)

    Hans,

    Thanks so much for the quick response. I'll go with the OnEvent for now as I'm still trying to get up to speed with the 2007 Ribbons, but its a great suggestion that I'll come back to later.

    Thanks again,
    Marty

Posting Permissions

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