Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Rich Text Memo Field Question

Status
Not open for further replies.

RolandR

Programmer
Mar 20, 2021
7
US
Is there a way to search an Access (2010) rich text memo Form field with VBA code to find if the HTML tag for the red color, or any other color for that matter, is being applied somewhere in that rich text memo Form field and if it is not, then perform some VBA code? I want to use that code in a Before Update Event for another field (checkbox) on the Form to determine if red formatting was used somewhere in the Memo field and if it wasn't not update the checkbox to true and then inform the user with a MsgBox that there was no red formatting in the Rich Text Memo Form field. Thanks.
 
Never mind. Turns out the InStr code will find the HTML snippet. You just have to be careful to limit the code being searched to something in HTML that will not be split across lines in the field being searched or InStr may not find it since it also evaluates Newline characters. Here is some sample code to do this search:

Private Sub subFindHtmlSnippet()

Dim varFound As Variant, strString1 As String, strString2 As String

strString2 = "color=red>" 'What HTML snippet are you looking for?
strString1 = Me![YourTextFieldWithRichText] 'Where are you searching for it?
varFound = InStr(1, strString1, strString2) 'Do the search
If varFound > 0 Then 'Search successful
'MsgBox "InStr returned: " & varFound 'For Testing
***Perform some code if found***
Else
'MsgBox "InStr returned: " & varFound 'For Testing
***Perform some code if NOT found***
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top