Convert RTF / HTML Field to Text - Access 2007

Posted on 2009-02-17
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

Question by:Wizard_IT
  • 5
  • 2
  • 2
  • +1
LVL 65

Accepted Solution

rockiroads earned 2000 total points
ID: 23663645
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


Author Comment

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

Author Comment

ID: 23668537

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 23668651
BTW - The password aren't valid if you thought I was NAIVE ;)
LVL 74

Expert Comment

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


Author Comment

ID: 23670032
I gathered that but wasn't 100% sure - hence the attached samples
Thanks for confirmation
LVL 65

Expert Comment

ID: 23672350
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.

Author Comment

ID: 24491401
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
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 25414445
So for the record, what was the final solution?

Expert Comment

ID: 32864347
You can also use the Application.PlainText Method or PlainText function.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question