how to find richtext codes for highlight, underline etc (1 Viewer)

Status
Not open for further replies.

CJ_London

Super Moderator
Staff member
Local time
Today, 19:12
Joined
Feb 19, 2013
Messages
16,553
You might use this with the objective of highlighting searched for text in a text field, or perhaps to format the date and time values in a single field a different colour (although date/time fields would then be text format). Will also work with numbers but they also will be converted to text. Note this is only applicable for access 2007 and later.

1. create a temporary table with a memo (or long text) field and set field to richtext
2. populate the table with some words and highlight/bold/underline as required
3. create a query based on the temporary table and in the query grid put

Expr1:[mymemofieldname] & " "

4. run the query and you will see something like

<div>hello <font style="BACKGROUND COLOR:#FFFF0"world</font></div>

to use this

5. in a query, create a column something like

highlighttext: "<div>" & Replace([myfield],"world","<font style='BACKGROUND-COLOR:#FFFF00'>world</font>") & "</div>"

note the use of single quotes
if myfield is a memo field already set as rich text and you don't want to preserve the existing formatting, then substitute [myfield] with PlainText([myfield]). You might need to do this if the formatting overlaps. For example if you are identifying 'World', then World will not be found because of the existing formatting effectively splitting the word - ...W</strong>orld....

note that highlighting does not work when the query is run - to see the effect, create a form (can be datasheet) and set the textbox text format to rich text.
 

isladogs

MVP / VIP
Local time
Today, 19:12
Joined
Jan 14, 2017
Messages
18,186
Hi

Thanks for this
I did exactly that & after a bit of tweaking got it working - example attached

One comment - although you need single quotes in the SQL expression as shown above, you will need to change them back to double quotes at the end or the text won't display the way you wanted.

Alternatively perhaps it would work with double " quotes?
 

Attachments

  • ReportWithHighlightedText.PNG
    ReportWithHighlightedText.PNG
    58.3 KB · Views: 742
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom