We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Convert RTF / HTML Field to Text - Access 2007

Wizard_IT asked
Medium Priority
Last Modified: 2013-11-27
I have a field in Access 2007 which is Rich Text and thus looks great within Access
However when I insert the data into Word via an Insert Database Field the codes come across with it
So I want to create a new field that is the TEXT version of the field for Mail Merge purposes

An Example of a field is as follows
<div>WSUS SP1</div>

<div>Running on argancap-fp</div>


I already have a function that converts most of the data but it leaves a lot of them and also doesn't translate Carriage Returns Properly
Code is as follows

Please advise what can convert a Rich Text properly

Thanks in advance

Function StripHTMLChars_V2(sStr)
  Dim iPos1 As Integer
    Dim iPos2 As Integer
    iPos1 = InStr(sStr, "<")
    Do While iPos1 > 0
        iPos2 = InStr(iPos1 + 1, sStr, ">")
        If iPos2 > 0 Then
            sStr = Left(sStr, iPos1 - 1) & Mid(sStr, iPos2 + 1)
            Exit Do
        End If
        iPos1 = InStr(sStr, "<")
    StripHTMLChars_V2 = sStr
End Function

Open in new window

Watch Question

Top Expert 2006
Do u have a richtextbox control available? You can use .text and .textrtf

eg  create a new rich txtbox control, set the rtf text to be your rtf text, then use .text to get the text part only

Function RemoveRTF(rtf)
    Dim ctlRtf As New RichTextBox
    ctlRtf.TextRTF = rtf
    RemoveRTF = ctlRtf.Text
End Function

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


i'll try - looks simple enough
Thanks - I shall try tomorrow as I'm tied up at the mo



Cannot use the above code - Have tried hanging it on a  form to test but cannot extract the text from the RTFObject - VB doesnt crash but an error along the lines of cannot reference is on the VBA screentip

The type of text contains

Do you think it best to work with a routine as above to strip out, baring in mind the blank lines !

<div><font face=Arial size=2>administrator tal2007</font></div>

<div><font face=Arial size=2>service-basilica tal2006 &nbsp;</font></div>

<div><font face=Arial size=2>service-besadmin tal2006 </font></div>

<div><font face=Arial size=2>service-backup tal2006 </font></div>

<div><font face=Arial size=2>service-spam tal2006</font></div>

<div><font face=Arial size=2>service-av tal2006 </font></div>

<div><font face=Arial size=2>&nbsp;</font></div>


The above displays the following on the screen
administrator tal2007
service-basilica tal2006  
service-besadmin tal2006
service-backup tal2006
service-spam tal2006
service-av tal2006


BTW - The password aren't valid if you thought I was NAIVE ;)
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Are we all aware that in Access 2007, "Rich Text" is actually HTML. (Not the true Rich Text format, rtf)?



I gathered that but wasn't 100% sure - hence the attached samples
Thanks for confirmation
Top Expert 2006

ok, so its html you want stripping. The example I gave was for rtf.

Im not sure where the problem lies looking at the example you posted. Looks like its working?

Can you give an example string that is messed up? i.e. what it looks like in word.


Hi Rockiroads
Its been a while since I looked at this but its cropped up again in the same system
I have tried your function but I am told teat the control in unavailable?
Compile Error
User-Defined Type Not Defined

How can I get around this - Thanks

Displaying the individual field objects on a report wors fine as Access deals with the formatting itself
However I need to build a Large Text Box of multiple records, based on date oriders etc..........

If I cant get this working I will need to include a Sub Report but then copying the data into Excel becomes an issue

Thanks in advance again Rockiroads
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

So for the record, what was the final solution?
Jim FaustSr. Data Quality Engineer / Independent Consultant

You can also use the Application.PlainText Method or PlainText function.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.