Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 45
  1. #16
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46

    Thanks for attaching it. I'm just super wary of downloading files, from anyone.

    (I realize that I've been attaching files myself.)

  2. #17
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Good day,

    What would you suggest using instead of the Replace function? Wracking my brains on this one. Did you happen to write something out? Appreciate any guidance.

  3. #18
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    to what purpose - why not use the replace function?

  4. #19
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    The problem that I am running into is keeping the text cases correct (I already tried using the vbBinaryCompare in the compare argument).

    Currently, if you search “a,” it replaces all “a” and “A” with a lowercase “a.” However, I want the txtToSearch to “maintain” its case.

    The vbBinaryCompare argument takes it halfway there. However, if you search for “a,” only the lower case “a”s will be highlighted.

    Let me know if that makes sense. I can clarify.

  5. #20
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Basically, I want the characters typed in the search to turn red in the search results. It’s almost like I want to disregard the case of the text in the search.

    Ex. “a” brings up the results “Apple”, “Test a”

  6. #21
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    characters typed in the search to turn red in the search results
    OK so you want to highlight 'A' but not as 'a' - so you are using a richtext field

    The way I have done that in the past is to find the actual characters using the mid and instr functions. The problem is you need to start with a 'plaintext' version then insert the formatting code and then return back to rich text

    strSearch = "abc"

    strText "It's as simple as ABC"

    Code:
    strTemp=plaintext(strText) 'to remove any formatting
    
    dim phrase as string
    
    strTemp=plaintext(strText) 'to remove any formatting
    strPhrase=mid(strTemp,instr(strTemp,strSearch),len(strSearch))
    strTemp=lreplace(strTemp,strPhrase,"<font....>" & strPhrase & "</font>",,1)
    strtext=replace(strTemp,vbcrlf,"<br>")
    that only replaces the first instance - you can use the instr+length of strSearch to set the replace start position to progress through strTemp so you are covered for Abc, aBc etc

    Technically you can just used this method on the richtext value, however it runs the risk of modifying existing html code (e.g. you are searching for 'font') which will just blow the whole thing up

  7. #22
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    dont be to wary, I the db came from you, remember.
    I just updated it.
    Attached Files Attached Files

  8. #23
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Thanks! I tried out the code and am getting the run-time error code 5 on the strPhrase line (I had to declare some of the variables.)

    Code:
    Function HighTest(strText As Variant, strSearch As String) As VariantDim strTemp As StringDim strPhrase As StringConst strcTagStart = "<font color=red>"Const strcTagEnd = "</font>"strTemp = PlainText(strText) 'to remove any formattingstrPhrase = Mid(strTemp, InStr(strTemp, strSearch), Len(strSearch))strTemp = Replace(strTemp, strPhrase, strcTagStart & strPhrase & strcTagEnd, , 1)strText = Replace(strTemp, vbCrLf, "<br>")End Function
    
    Attached Thumbnails Attached Thumbnails Run time error 5.PNG  

  9. #24
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Code:
    Function HighTest(strText As Variant, strSearch As String) As Variant
     
    Dim strTemp As String
    Dim strPhrase As String
     
    Const strcTagStart = "<font color=red>"
    Const strcTagEnd = "</font>"
     
     
    strTemp = PlainText(strText) 'to remove any formatting
    strPhrase = Mid(strTemp, InStr(strTemp, strSearch), Len(strSearch))
    strTemp = Replace(strTemp, strPhrase, strcTagStart & strPhrase & strcTagEnd, , 1)
    strText = Replace(strTemp, vbCrLf, "<br>")
     
     
    End Function

  10. #25
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Dang, I really want to see your edits, but I am unable to open it.

  11. #26
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Quote Originally Posted by Pianopizza5 View Post
    Thanks! I tried out the code and am getting the run-time error code 5 on the strPhrase line (I had to declare some of the variables.)

    Code:
    Function HighTest(strText As Variant, strSearch As String) As VariantDim strTemp As StringDim strPhrase As StringConst strcTagStart = "<font color=red>"Const strcTagEnd = "</font>"strTemp = PlainText(strText) 'to remove any formattingstrPhrase = Mid(strTemp, InStr(strTemp, strSearch), Len(strSearch))strTemp = Replace(strTemp, strPhrase, strcTagStart & strPhrase & strcTagEnd, , 1)strText = Replace(strTemp, vbCrLf, "<br>")End Function
    
    Works for me, in that it runs.

    Code:
    ? hightest("Always","ways")
    Al<font color=red>ways</font>
    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

  12. #27
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    SearchWSpacesExampleStrCode.accdb.zip

    Line 11: strPhrase = Mid...

  13. #28
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Show what you are passing in.
    Plus learn to walk your code with F8 and breakpoints.
    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

  14. #29
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    Perhaps strsearch is zero length? And why declare strtext as variant?

  15. #30
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    just realised this is the onchange event - so the control will not have been updated, You need to use strSearch.text

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-26-2020, 02:01 AM
  2. Replies: 5
    Last Post: 02-13-2019, 12:42 PM
  3. Replies: 1
    Last Post: 05-03-2013, 01:40 PM
  4. Remove blank spaces after strings in fields
    By Modify_inc in forum Access
    Replies: 8
    Last Post: 08-18-2012, 06:30 PM
  5. Blank spaces at start of entries
    By rcmglover in forum Access
    Replies: 2
    Last Post: 03-26-2010, 10:42 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