Hmmm... No@smig
Didn't you ask almost the same thing before in this thread https://www.access-programmers.co.u...e-the-reachtext-tool-bar.310396/#post-1680110
Thanks, as you noticed there is still more text to be removed after the first <Font...... till the enclosure with >This gets a little complicated because of the varied length of the FONT opening tag. Might need a custom function.
If you want to actually modify saved data, run an UPDATE action SQL.
dim s as string
dim e as long
e=instr(mystring,"<Font")
while e <>0
s=mid(mystring,e,instr(e,mystring,">")-e+1)
mystring=replace(mystring,s,"",1,1)
mystring=replace(mystring,"</font>","",1,1)
e=instr(mystring,"<Font")
wend
Public Function RemoveFont(strD As String) As String
Dim strA As String, strB As String
If InStr(strD, "<Font") > 0 Then
strA = Left(strD, InStr(strD, "<Font") - 1)
strB = Mid(strD, InStr(strD, "<Font"))
strB = Replace(Mid(strB, InStr(strB, ">") + 1), "</Font>", "")
End If
RemoveFont = strA & strB
End Function
Public Function RemoveRichTextTag(ByVal pRichText As String, ParamArray pTagName() As Variant) As Variant
Dim sPattern As String, v As Variant
If Trim(pRichText & "") = "" Then Exit Function
With CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = True
For Each v In pTagName
sPattern = "<" & v & "[^><]*>|<." & v & "[^><]*>"
.Pattern = sPattern
'Debug.Print .TEST(pRichText)
pRichText = .Replace(pRichText, "")
Next
End With
RemoveRichTextTag = pRichText
End Function
still, RegExp can remove any RichText Tags.
to remove the Font tag:
anotherTextbox = RemoveRichTextTag(Me.theRichTextbox, "font")
to remove the Div and the Font tag:
anotherTextbox = RemoveRichTextTag(Me.theRichTextbox, "font", "div") 'you can interchange the font/div.
copy in a new Module:
Code:Public Function RemoveRichTextTag(ByVal pRichText As String, ParamArray pTagName() As Variant) As Variant Dim sPattern As String, v As Variant If Trim(pRichText & "") = "" Then Exit Function With CreateObject("VBScript.RegExp") .Global = True .IgnoreCase = True For Each v In pTagName sPattern = "<" & v & "[^><]*>|<." & v & "[^><]*>" .Pattern = sPattern 'Debug.Print .TEST(pRichText) pRichText = .Replace(pRichText, "") Next End With RemoveRichTextTag = pRichText End Function
UPDATE [Materials] SET [MaterialDescription] = Replace(Replace([MaterialDescription],"<FONT STYLE='BACKGROUND-COLOR:#FFFF00'>",""),"</FONT>","")
CurrentDb.Execute "UPDATE [Materials] SET [MaterialDescription] = Replace(Replace([MaterialDescription],'<FONT STYLE=''BACKGROUND-COLOR:#FFFF00''>',''),'</FONT>','')"
Public Function RemoveRichTextTag2(ByVal pRichText As String, ParamArray pTagName() As Variant) As Variant
Dim sPattern As String, v As Variant
Dim matches
Dim i As Integer, j As Integer
Dim l As Long
Dim bolOK As Boolean
If Trim(pRichText & "") = "" Then Exit Function
With CreateObject("VBScript.RegExp")
.Global = True
.IgnoreCase = True
For Each v In pTagName
If InStr(v, "<Font") > 0 Then
v = Replace(Replace(v, "<", ""), ">", "")
sPattern = "<" & v & "[^><]*>|<.font[^><]*>"
Else
sPattern = "<" & v & "[^><]*>|<." & v & "[^><]*>"
End If
.Pattern = sPattern
'Debug.Print .TEST(pRichText)
Set matches = .Execute(pRichText)
For i = 0 To matches.count - 1
bolOK = False
If matches(i) Like "<font*" Then
j = 1
bolOK = True
Else
j = j + 1
If j < 3 Then
bolOK = True
End If
End If
If bolOK Then
l = InStr(1, pRichText, matches(i))
'Debug.Print matches(i)
pRichText = Left(pRichText, l - 1) & Mid(pRichText, l + Len(matches(i)))
End If
Next
Next
End With
RemoveRichTextTag2 = pRichText
End Function
Yes, and also eliminate the closing tag.
If you want to run a query object:
If you want to execute in VBA - note doubled apostrophes embedded in the string which escapes special character so it will be treated as normal text:Code:UPDATE [Materials] SET [MaterialDescription] = Replace(Replace([MaterialDescription],"<FONT STYLE='BACKGROUND-COLOR:#FFFF00'>",""),"</FONT>","")
Code:CurrentDb.Execute "UPDATE [Materials] SET [MaterialDescription] = Replace(Replace([MaterialDescription],'<FONT STYLE=''BACKGROUND-COLOR:#FFFF00''>',''),'</FONT>','')"
this is a modified version
Code:Public Function RemoveRichTextTag2(ByVal pRichText As String, ParamArray pTagName() As Variant) As Variant Dim sPattern As String, v As Variant Dim matches Dim i As Integer, j As Integer Dim l As Long Dim bolOK As Boolean If Trim(pRichText & "") = "" Then Exit Function With CreateObject("VBScript.RegExp") .Global = True .IgnoreCase = True For Each v In pTagName If InStr(v, "<Font") > 0 Then v = Replace(Replace(v, "<", ""), ">", "") sPattern = "<" & v & "[^><]*>|<.font[^><]*>" Else sPattern = "<" & v & "[^><]*>|<." & v & "[^><]*>" End If .Pattern = sPattern 'Debug.Print .TEST(pRichText) Set matches = .Execute(pRichText) For i = 0 To matches.count - 1 bolOK = False If matches(i) Like "<font*" Then j = 1 bolOK = True Else j = j + 1 If j < 3 Then bolOK = True End If End If If bolOK Then l = InStr(1, pRichText, matches(i)) 'Debug.Print matches(i) pRichText = Left(pRichText, l - 1) & Mid(pRichText, l + Len(matches(i))) End If Next Next End With RemoveRichTextTag2 = pRichText End Function
UPDATE [Materials] SET [MaterialDescription] = RemoveRichTextTag2([MaterialDescription], "<FONT STYLE='BACKGROUND-COLOR:#FFFF00'>")