Results 1 to 5 of 5
  1. #1
    bburton12@comcast.net is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    11

    How to highlight selected text from a textbox by pressing a button


    Hello. I have a form where I enter information into a textbox. I would like to be able to select text in the textbox and highlight it in yellow (maybe by selecting the text and pressing a button on the form. Is this possible? Thank you.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the textbox (and the underlying field) needs to be set as richtext. then use the formatting facilities on the ribbon to highlight as required

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Not sure I agree; then again it seems I often don't understand the problem or explanation (I'm too literal I guess). In case this is what you had in mind, here's something you can try using the doubleclick event of a textbox-
    Code:
    If Not IsNull(Me.txtProp) Then
    With Me.txtProp
        .SelLength = Len(Me.txtProp)
        .BackColor = vbYellow
    End With
    Me.Repaint
    Else
    Me.txtProp.BackColor = vbWhite
    End If
    txtProp is the name of the control on my form. It's not perfect because it doesn't update the control, which means no effect unless you move off of it first. This should be rectified if you end up using a button, or you could use a different event (perhaps AfterUpdate). Let me know if you use it but need help tweaking it. I have to sign off for now.
    Last edited by Micron; 05-02-2017 at 03:58 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    or if it is always to be highlight yellow. Use code something like this in your form module

    Code:
    Option Compare Database
    Option Explicit
    
    Dim selected As String
    
    Private Sub Command20_Click()
    
        If Nz(selected) <> "" Then RTCtrl = Replace(RTCtrl, selected, "<font style=""BACKGROUND-COLOR:#FFFF00"">" & selected & "</font>")
    
    End Sub
    
    Private Sub RTCtrl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        
        selected = Nz(RTCtrl.SelText)
    
    End Sub
    where RTCtrl is the name of your rich text control and command20 is the name of the button that does the highlighting when clicked

  5. #5
    bburton12@comcast.net is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    11
    Thank you. I was able to implement the code, but switching it to rich text solved my problem.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-26-2016, 05:28 AM
  2. Replies: 3
    Last Post: 03-11-2015, 03:28 PM
  3. Replies: 4
    Last Post: 10-23-2014, 12:21 PM
  4. Replies: 3
    Last Post: 07-09-2014, 02:49 PM
  5. how can i highlight a selected row in form?
    By joe55555 in forum Access
    Replies: 4
    Last Post: 08-29-2013, 01:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums