Wizard_IT
asked on
Convert RTF / HTML Field to Text - Access 2007
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 2.0.0.2620 SP1</div>
<div>Running on argancap-fp</div>
<div> </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
Paul
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 2.0.0.2620 SP1</div>
<div>Running on argancap-fp</div>
<div> </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
Paul
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)
Else
Exit Do
End If
iPos1 = InStr(sStr, "<")
Loop
StripHTMLChars_V2 = sStr
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rockiroads
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 </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> </font></div>
<div> </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
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 </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> </font></div>
<div> </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
ASKER
BTW - The password aren't valid if you thought I was NAIVE ;)
Are we all aware that in Access 2007, "Rich Text" is actually HTML. (Not the true Rich Text format, rtf)?
Jeff
Jeff
ASKER
I gathered that but wasn't 100% sure - hence the attached samples
Thanks for confirmation
Thanks for confirmation
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.
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.
ASKER
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
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
So for the record, what was the final solution?
You can also use the Application.PlainText Method or PlainText function.
ASKER
Thanks - I shall try tomorrow as I'm tied up at the mo