Reputation: 3
In an ms access rich text textbox I can select any part of the text and a dialog box shows up then I can click a color on the highlight dropdown box and the text is highlighted. I want to be able to do the same with vba but can't seem to get the syntax to do the highlighting. I can use selstart and sellength to select the text but unable to find the syntax for highlighting.
[Forms]![myform]![mytextbox].SelText.Highlight = vbGreen
run-time error 424 object required
Update:
Here is my code:
Private Sub Label4_Click()
Dim selSt, selLen As Integer
Dim selT As String
Dim strm As String
With Me.Text0
.SetFocus
selSt = .selStart
selLen = .SelLength
selT = .SelText
strm = "<font style='BACKGROUND-COLOR:#32F6F6'>" & selT & "</font>"
Me.Text0 = Replace(.Value, selT, strm)
.selStart = selSt
.SelLength = selLen
End With
End Sub
So one ex i selected 384 characters and only 130 were highlighted. Another ex i selected 93 chr's with a bulleted line to the end of the sentence and it doesn't do anything but when i select that same line with only 80 of the chr's it worked??
Upvotes: 0
Views: 168
Reputation: 21379
If I remember correctly, Access uses pre-HTML5 tags for rich text formatting. The set of supported tags is limited. This works for me:
Private Sub Command54_Click()
Dim strS As String, strM As String
With Me.Text52
.SetFocus
.SelStart = 5
.SelLength = 4
strS = .SelText
strM = "<font color=""red"">" & strS & "</font>"
.Value = Replace(.Value, strS, strM)
End With
End Sub
Upvotes: 1