Rich formatted text that includes data from fields

Published 16 January 08 12:45 PM

The other day I was working on a report where I wanted to build a sentence that included multiple fields from a record but I wanted to use rich text formatting to provide contrast. My scenario was pretty simple in that I wanted a bold title with a date trailing it. Some think like:

This was a great book, reviewed on 1/12/2007

My problem was both fields were pulled from normal text fields and I wanted the data to trail immediately after the variable length title.

Here is how I made it work inside Access.

  1. Add a control to the form/report.
  2. Change the control's Text Format property to Rich Text.
  3. Construct simple HTML in the control source. Mine looked something like:

    ="<div><strong>" & [Summary] & "</strong>, <font color=""#A5A5A5""><em> reviewed on " & [ReviewDate] & "</em></font></div>"

For a number of reasons the rich text control doesn't support the full range of HTML but rather a limited subset of HTML focused around formatting text. If you stick to the list of HTML tags and attributes below you should be safe:

<font face="Arial Black" size=3 color="#A5A5A5" style="BACKGROUND-COLOR:#FFFF00">
<strong>
<em>
<u>
<br>
<div align=right dir=RTL>
<blockquote>
<ol> and <li> for number
<ul> and <li> for bulleted lists

One gotcha you have to work around is handling quotes around attributes. Technically speaking all attributes in HTML should be surrounded by quotes. To have the string evaluate by the expression service to something that gets passed to the rich text control with the right syntax you need to use double quotes for any quote. In the example above <font color=""#A5A5A5""> will evaluate to <font color="#A5A5A5">. Alan Browne has published a good article for new users on Quotations marks within quotes.

Lastly, there is a quick way to generate the HTML you need and make sure it is compliant with the Rich Text control. Create a test table with one rich text control field on it. Create a simple form with two controls bound to the rich text field. Change one of the text boxes to Text Format = Plain Text. Now you can see the formatted version and the HTML.

Rich Text

Enjoy!

by clintc

Comments

# Tom Wickerath said on January 17, 2008 5:17 AM:

Hi Clint,

I would find it very useful if the Access Team could put out a tool that allowed one to convert formatted text stored with the rich text format (FMS Total Access Memo or Stephen Leban's Rich Text Control) to the new HTML format used by Access 2007. Maybe also allow conversion in both directions as well.

# clintc said on January 17, 2008 8:03 AM:

Great idea. I think it is a great tool for someone in the community to build. The schedule for Access 14 is really full.

# Oli-S (freakazeud) said on January 17, 2008 11:51 AM:

Tom...take all formatting syntax found here:

http://search.cpan.org/~sburke/RTF-Writer/lib/RTF/Cookbook.pod#FORMATTING_CODES

and replace it with appropriate HTML tags. Should only take you a couple of weeks to do ;)

# Tom Wickerath said on January 17, 2008 12:24 PM:

Oli -

Sounds like a great first assignment for a bright young Computer Science graduate to tackle, if this person ends up taking a position with Microsoft.  <smile>

# clintc said on January 17, 2008 12:45 PM:

I keep trying to get Oli to interview! He says he needs to graduate first. You know, our founder did pretty well without a degree.

# AL said on January 17, 2008 3:40 PM:

I think it might be nice to have an HTML "RTF" box that actually supported all of HTML, and that came complete with support for data-bound AJAX controls.

Or maybe support for MS Word lite in a lightweight RTF box.

The current RTF/HTML box is so limited, why not just use the FMS control?

New Comments to this post are disabled
Page view tracker