I found the following online and after a couple of tweaks it works well to highlight each instance of a single word in the 'Synopsis' field of a report.
Where I'm getting stumped is in adapting it so that it can change the colour and size of all words selected by the user.
The code above loops through the selection perfectly, but - as you can see - each iteration overwrites the previous, meaning that only the last word entered is coloured on the final report.
Is there an easy way for it to highlight however many words are entered?
If it were on a form, I know how to do it, but the fact that the report is being changed in design view has me puzzled, since the text isn't yet displayed.
Code:
Sub Highlight_Keywords()
Dim RstKey As Recordset
Dim strSearch As String
Dim strTemp As String
Dim strTempEnd As String
Set RstKey = Forms!frmCRTTBControl!frmCRCriteriaTab!frmCRSystemKeyword.Form.RecordsetClone
If RstKey.RecordCount <> 0 Then
RstKey.MoveFirst
Do While Not RstKey.EOF
strSearch = RstKey!keyword
Reports!rptPDResults!txtSynopsis.ControlSource = "=IIf([Synopsis] Is Null, Null, Replace([Synopsis], """ & strSearch & """, ""<b><font color=red size = 4>" & strSearch & "</font></b>""))"
RstKey.MoveNext
Loop
End If
RstKey.Close
Set RstKey = Nothing
End Sub
The code above loops through the selection perfectly, but - as you can see - each iteration overwrites the previous, meaning that only the last word entered is coloured on the final report.
Is there an easy way for it to highlight however many words are entered?
If it were on a form, I know how to do it, but the fact that the report is being changed in design view has me puzzled, since the text isn't yet displayed.