Results 1 to 3 of 3
  1. #1
    vinzanitee is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    1

    VBA to highlight textbox

    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:



    to:



    Code:
    Public gPhoneFltr As String
    Code:
    
    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


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    in text box GOT FOCUS
    txtBox.backcolor = vbYellow

    in LOST FOCUS
    txtBox.backcolor = vbWhite

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Crossposted same time today and with replies
    https://www.access-programmers.co.uk...extbox.316480/
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2017, 10:37 AM
  2. Replies: 3
    Last Post: 07-09-2014, 02:49 PM
  3. Highlight Parameter value in report
    By Hank153 in forum Reports
    Replies: 3
    Last Post: 01-14-2013, 05:54 PM
  4. Replies: 12
    Last Post: 06-08-2012, 02:37 AM
  5. Replies: 2
    Last Post: 12-07-2010, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums