Rich Text in Memo Fields in Access 2007

How to use Rich Text in memo fields in Access 2007.

Access Archon #157


Introduction

Over the years, the functionality of Access forms and reports has been significantly upgraded. In Access 2007, one long-requested feature has finally arrived in a workable form (I recall an early and unreliable implementation that made a brief appearance in Access 95). Memo fields can now store and display rich text, using the Text Align property, which takes a value of either Plain Text or Rich Text. When you select Rich Text for this property, you can apply various fonts, colors, and other attributes to selected portions of text in a table field or a control bound to that field.

In earlier versions of Office, if you wanted to generate a letter or other document including a block of text with color, bolding, or other attributes applied to selected words or phrases within the block, you had to create a Word letter, and use Word’s formatting features. In Access 2007, you can create Access reports with varied formatting within text blocks, displaying text entered into Access memo fields in a textbox on a form.


Using Rich Text

To create a field that can store data in Rich Text format (behind the scenes, this is done using HTML code, but you don’t have to worry about writing the code), start by creating a table field of the Memo data type, and selecting Rich Text as the Text Format value (see Figure A).

Right-click here to download pictures. To help protect your privacy, Outlook prevented automatic download of this picture from the Internet.
Figure A.  Creating a Memo field to hold Rich Text data

Create a form bound to the table with the Memo field; you can now enter data into this textbox control and format it with different fonts, color, bolding, and other attributes, as you would while working in a Word document. When you place the cursor into a control with Rich Text enabled, a formatting group on the Home tab of the Ribbon is enabled, with a variety of formatting selections.  Figure B shows a form control bound to a Rich Text-enabled Memo field, with a variety of text formatting, and the Rich Text group on the Ribbon.

Right-click here to download pictures. To help protect your privacy, Outlook prevented automatic download of this picture from the Internet.
Figure B.  The Rich Text group on the Home tab of the Access 2007 Ribbon

 Once you have applied formatting to the text on a form, you can create a report based on the table, and the formatting will display on the report as well (see Figure C).

Right-click here to download pictures. To help protect your privacy, Outlook prevented automatic download of this picture from the Internet.
Figure C.  A report displaying Rich Text from a form field

If you select a block of text in a Rich Text–enabled Memo field, you will see a floating toolbar that lets you apply some formatting, including bulleting, numbering, indenting and outdenting, similar to Word (see Figure D).  Indenting and outdenting work fine, but if you apply bullets or numbering from this toolbar, you will get the bullets or numbers, but the text that runs over one line won’t be indented properly, as shown in Figure E. For this reason, I recommend against using bullets and numbering, except for lists where all the items are no more than one line in length.

Right-click here to download pictures. To help protect your privacy, Outlook prevented automatic download of this picture from the Internet.
Figure D.  Applying bulleting to a list from the floating toolbar in a Rich Text field.

Right-click here to download pictures. To help protect your privacy, Outlook prevented automatic download of this picture from the Internet.
Figure E.  Incorrect indentation of bulleted items in a Rich Text field.

You can copy and paste formatted text from a Word document into a Memo field with Rich Text enabled (or a textbox bound to such a field), and the formatting will be preserved. However, bullets and numbered lists won’t be aligned correctly, so it is best to turn off those features before copying text to Access.

Note:  This article is adapted from the section on Rich Text in my upcoming Wiley book, Access™ 2007 VBA Bible For Data-Centric Microsoft® Applications, which should be out in a month or so.  For more details about using Rich Text, see Chapter 1 of this book.


References

The code in the sample database doesn’t need any extra references.


Supporting Files

The zip file containing this article, in Word format, plus the supporting file(s), may be downloaded from the Access Archon page of my Web site.  It is accarch157.zip, which is the last entry in the table of Access Archon columns for Access Watch.











Document Name

Document Type

Place in

RichText.accdb

Access 2007 database

Wherever you want