How To Work With Microsoft Access RTF Fields

Access RTF Menu

Today, I thought I’d touch upon RTF (Rich Text Field(s)).

If you’ve looked over my

you’ll know I’m not a huge fan of RTF.

Why?

Well, RTF is simply a crippled implementation of proper HTML.  I’ve always thought that if you’re going to do something, then do it properly or don’t do it at all! In this instance, that would mean implementing proper HTML, but that’s obviously not the view Microsoft takes of things!!!

At the time of writing my Improved HTML article, RTF could not do basic HTML things like:

  • Justify text
  • Insert links
  • Insert tables
  • Insert images/media
  • Format text
    • Strikethrough
    • Superscript
    • Subscript
  • Use predefined formats (p, h1, h2, h3, …)
  • and the list goes on, and on, and …

That’s neither here or there for today’s subject matter though.

I know many people use RTF because it is convenient, so I thought I’d cover a couple quick issues/questions that sometimes come up in forums.

Creating An RTF Field

It all starts in your Table design.

You insert a new field and set it’s data type to Long Text(Yes, only Long Text supports RTF because RTF adds all sorts of HTML markup to your text requiring the extra storage space that Long Text enables).

Then you need to set the field’s “Text Format” to “Rich Text”.

Now you have a RTF field, ready for use!

Access RTF Field Setup

Viewing The Raw Text Of An RTF Field

At times one may which to extract the Text from an RTF field without any of the Markup or formatting associated with RTF fields.

I covered a couple ways to do this in my article:

in which I elaborate that you can either use a VBA function or the built-in PlainText() function. Either can be used in queries, form, reports and VBA.

In A Query

It is very easy to use a query to return the plain text of an RTF field.  It is just a question of building an expression using the PlainText() function.

Access RTF Query PlainText

SELECT ID, MyText AS [RTF Text], PlainText([MyText]) AS [Plain Text]
FROM RTFText;
Note
Be aware that the resulting field will be read-only.

In A Form

Obviously, you can bind to a query that already uses PlainText to return the sanitized value.  If not, you can easily do so directly in a form by setting the control’s Control Source.

=PlainText([YourFieldName])

Note
Be aware that the resulting field/control will be read-only.

 

Viewing The RTF’s HTML Markup

This is another question that pops up every once and a while in forums and is easy to achieve.

For this, it is simply a question of getting Access to display the RTF as Plain Text rather than RTF.

In A Query

To get a query to display the HTML markup of an RTF field it is simply a question of changing the default Text Format property for the RTF field from Rich Text to Plain Text.

Access RTF Query HTML

SELECT RTFText.ID, RTFText.MyText AS [RTF Text], RTFText.MyText AS [HTML Markup]
FROM RTFText;

Note: This is a fully editable field.

In A Form

As with getting plain text, you can bind to a query that already returns the HTML markup.  If not, you can easily do so directly in a form by setting the control’s Control Source.

= ([YourFieldName])

and then set the Text Format to Plain Text

Note
Be aware that the resulting field/control will be read-only.

True HTML

If you wish to get the true full power of HTML in your database, be sure to check out my article

 

A Few Resources On The Subject

2 responses on “How To Work With Microsoft Access RTF Fields

  1. Chris Gibbings

    Thanks for all your great information Daniel. Another issue I have come across with MS Access RTF is that it messes with the builtin Find and Replace. I have found that:
    – the Find button works okay
    – the Replace button often highlights the wrong text but replaces the correct text
    – the Replace All button often replaces the wrong text, which is obviously a disaster.
    Find and Replace is such a useful feature for users – I just wish that Microsfot would fix it or I could turn off the ability to use “Replace All”.

    1. Daniel Pineault Post author

      I was not aware of that issue. Thank you for sharing.

      Can I ask you what version of Access you are running? (version, build, bitness) Thanks