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, 18:56
Joined
Feb 19, 2013
Messages
12,128
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

CID Moderator
Staff member
Local time
Today, 18:56
Joined
Jan 14, 2017
Messages
13,385
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

CJ_London

Super Moderator
Staff member
Local time
Today, 18:56
Joined
Feb 19, 2013
Messages
12,128
here is a simple db to make life a bit simpler
 

Attachments

Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom