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.
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.
the textbox (and the underlying field) needs to be set as richtext. then use the formatting facilities on the ribbon to highlight as required
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-
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.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
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.
or if it is always to be highlight yellow. Use code something like this in your form module
where RTCtrl is the name of your rich text control and command20 is the name of the button that does the highlighting when clickedCode: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
Thank you. I was able to implement the code, but switching it to rich text solved my problem.