Solved Format RichText to PlainText but keep Line Breaks (1 Viewer)

Saphirah

Active member
Local time
Today, 20:04
Joined
Apr 5, 2020
Messages
163
Hello everyone,

I have a rich text field. Now whenever a user copy pasts text from the internet into the text field, the formatting might be off, due to other fonts, text sizes etc...
That is why i added a button to reset the formatting of the text. Using the PlainText function you can convert RichText to a simple text string.

Code:
Private Sub ResetFormat_Btn_Click()
    Beschreibung_Fld = PlainText(Beschreibung_Fld)
End Sub

But this will remove line breaks, which is not my intention. How can i reset the formatting to the system default, without removing the line breaks?
Thank you very much!
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:04
Joined
Sep 21, 2011
Messages
14,217
Substitiute the linebreaks for something and then substitute back after the PlainText() function?
 

Saphirah

Active member
Local time
Today, 20:04
Joined
Apr 5, 2020
Messages
163
Thank you, i tried that out. The problem is, the rich text is not storing the line breaks as <br>.

The Text is surrounded by <div>'s. Whenever i print the content of my text field i get this:
Code:
<div>Line1</div>

<div>Line2</div>

<div>Line3</div>

So i came up with this solution. Feel free to improve me, the code is pretty long...

Code:
Private Sub ResetFormat_Btn_Click()
    Beschreibung_Fld.SetFocus
    Dim newStr As String: newStr = Me!Beschreibung_Fld
    newStr = Replace(newStr, "<div>", "")
    'Replace Div closer with a random String
    newStr = Replace(newStr, "</div>", "_kaerBeniL_")
    newStr = PlainText(newStr)
    newStr = Replace(newStr, "_kaerBeniL_", "<br>")
    Beschreibung = Replace(newStr, "<br> ", "<br>")
    Beschreibung_Fld.Requery
End Sub
 

Users who are viewing this thread

Top Bottom