I have a subform that is a continuous form that lists the text elements for each record in the parent form. In this case, the parent form lists a particular claim number, and the subform provides the text elements of that claim. I found some clever code online that uses an unbound text box on top of the text element to reproduce the claim text but with a select word highlighted. The particular word comes from a related list of words. But sometimes, the word in the claim is not exactly the same as the word on this list. For example the word on the list might be "run" but I also want to highlight "running" or "runs." I've explored various ways to identify different variations like, for example finding "run" in the text and then finding the rest of the word using InStr() and Mid(), etc. This worked, in general, but only for the first record. Even though the basic process works for all the records in the continuous form, I can't figure out how to programmatically look at the text of each individual record to evaluate what I need to search for. I've tried some RecordSet looping, but it seems to always just look at the first record.
Looking at some other posts I get the feeling that this might not be possible, but would appreciate any insight. The code below works. Just trying to figure out how to adapt this so I can work with text in the individual records and highlight variations of a word.
Thanks.
Public Sub Form_Current()
Dim ctl As Control
On Error GoTo Err_Handler
'Purpose: Highlight matches in txtSearchDisplay.
Dim strField As String 'The field to search
Dim strSearchValue As String 'The value to find
Dim strControlSource As String 'ControlSource for displaying match.
Const strcWildcard = "*" 'Some other back ends use %
'HTML tags for highlighting matches. Could be just "<b>" and "</b>".
Const strcTagStart = "<font color=""""red"""">"
Const strcTagEnd = "</font>"
'Search for claim term value in claim element text.
strField = "ClaimElementText" 'Field containing claim text
strSearchValue = Forms![frmWords].ClaimTerm 'This is the word to highlight
'Control Source for the text box to display matches.
strControlSource = "=IIf(" & strField & " Is Null, Null, " & _
"Replace(" & strField & ", """ & strSearchValue & """, """ & _
strcTagStart & strSearchValue & strcTagEnd & """))"
With Forms![frmWords]![sbfmClaims].Form![sbfrmClaimText].Form!txtSearchDisplay
.ControlSource = strControlSource
.Visible = True
.BackColor = RGB(255, 255, 255)
End With
'This is necessary to get the term highlighting to show up on first limitation.
Forms![frmWords]![sbfmClaims].Form![sbfrmClaimText].Form!txtSearchDisplay.SetFocus
Exit_Handler:
Exit Sub
Err_Handler:
Resume Exit_Handler
End Sub