vinzanitee
02-24-2021, 05:45 AM
Hi Team, desperately need your expertise. I have this code that will highlight the keyword result query. This time I want to highlight the textbox of the results instead of the text itself. Thank you in advance!
From:
https://www.access-programmers.co.uk/forums/attachments/capture-jpg.89483/
to:
https://www.access-programmers.co.uk/forums/attachments/4-jpg.89484/
Public gPhoneFltr As String
Public Const FONT_COLOR = "#FFFFFF"
Public Const FONT_BGCOLOR = "#FF6600"
Public Const gBasicHTMLTemplate = "<div>{3}<font color={1} style=""BACKGROUND-COLOR:{2}"">{4}</font>{5}</div>"
Public Function getPhoneFltr() As String
getPhoneFltr = gPhoneFltr
End Function
Public Function getBasicHTMLTemplate() As String
getBasicHTMLTemplate = gBasicHTMLTemplate
End Function
Public Function formatMatch(ByRef oValue As Variant, ByRef oMatch As Variant, ByRef oTemplate As Variant) As String
Dim sValue As String
Dim sMatch As String
Dim sTemplate As String
Dim iPos As String
Dim beforeMatch As String
Dim onMatch As String
Dim afterMatch As String
sValue = Nz(oValue, "")
sMatch = Nz(oMatch, "")
sTemplate = Nz(oTemplate, "")
formatMatch = sValue
If Len(sValue) > 0 And Len(sMatch) > 0 And Len(sTemplate) > 0 Then
iPos = InStr(1, sValue, sMatch, vbDatabaseCompare)
If iPos > 0 Then
iPos = iPos - 1
formatMatch = sTemplate
' Color
formatMatch = Replace(formatMatch, "{1}", FONT_COLOR)
formatMatch = Replace(formatMatch, "{2}", FONT_BGCOLOR)
' If sValue = sMatch Then
' formatMatch = Replace(formatMatch, "{3}", "")
' onMatch = Mid(sValue, 0, Len(sMatch))
' formatMatch = Replace(formatMatch, "{4}", onMatch)
' formatMatch = Replace(formatMatch, "{5}", "")
' Else
' Before Match
beforeMatch = Mid(sValue, 1, iPos)
If iPos - 1 > 0 Then
formatMatch = Replace(formatMatch, "{3}", beforeMatch) 'Left(sValue, iPos))
Else
formatMatch = Replace(formatMatch, "{3}", "")
End If
' Match
onMatch = Mid(sValue, iPos + 1, Len(sMatch))
formatMatch = Replace(formatMatch, "{4}", onMatch)
' After Match
afterMatch = Mid(sValue, iPos + 1 + Len(sMatch))
If (iPos - 1) + Len(sMatch) < Len(sValue) Then
formatMatch = Replace(formatMatch, "{5}", afterMatch)
Else
formatMatch = Replace(formatMatch, "{5}", "")
End If
End If
' End If
End If
End Function
From:
https://www.access-programmers.co.uk/forums/attachments/capture-jpg.89483/
to:
https://www.access-programmers.co.uk/forums/attachments/4-jpg.89484/
Public gPhoneFltr As String
Public Const FONT_COLOR = "#FFFFFF"
Public Const FONT_BGCOLOR = "#FF6600"
Public Const gBasicHTMLTemplate = "<div>{3}<font color={1} style=""BACKGROUND-COLOR:{2}"">{4}</font>{5}</div>"
Public Function getPhoneFltr() As String
getPhoneFltr = gPhoneFltr
End Function
Public Function getBasicHTMLTemplate() As String
getBasicHTMLTemplate = gBasicHTMLTemplate
End Function
Public Function formatMatch(ByRef oValue As Variant, ByRef oMatch As Variant, ByRef oTemplate As Variant) As String
Dim sValue As String
Dim sMatch As String
Dim sTemplate As String
Dim iPos As String
Dim beforeMatch As String
Dim onMatch As String
Dim afterMatch As String
sValue = Nz(oValue, "")
sMatch = Nz(oMatch, "")
sTemplate = Nz(oTemplate, "")
formatMatch = sValue
If Len(sValue) > 0 And Len(sMatch) > 0 And Len(sTemplate) > 0 Then
iPos = InStr(1, sValue, sMatch, vbDatabaseCompare)
If iPos > 0 Then
iPos = iPos - 1
formatMatch = sTemplate
' Color
formatMatch = Replace(formatMatch, "{1}", FONT_COLOR)
formatMatch = Replace(formatMatch, "{2}", FONT_BGCOLOR)
' If sValue = sMatch Then
' formatMatch = Replace(formatMatch, "{3}", "")
' onMatch = Mid(sValue, 0, Len(sMatch))
' formatMatch = Replace(formatMatch, "{4}", onMatch)
' formatMatch = Replace(formatMatch, "{5}", "")
' Else
' Before Match
beforeMatch = Mid(sValue, 1, iPos)
If iPos - 1 > 0 Then
formatMatch = Replace(formatMatch, "{3}", beforeMatch) 'Left(sValue, iPos))
Else
formatMatch = Replace(formatMatch, "{3}", "")
End If
' Match
onMatch = Mid(sValue, iPos + 1, Len(sMatch))
formatMatch = Replace(formatMatch, "{4}", onMatch)
' After Match
afterMatch = Mid(sValue, iPos + 1 + Len(sMatch))
If (iPos - 1) + Len(sMatch) < Len(sValue) Then
formatMatch = Replace(formatMatch, "{5}", afterMatch)
Else
formatMatch = Replace(formatMatch, "{5}", "")
End If
End If
' End If
End If
End Function