Page 3 of 3 FirstFirst 123
Results 31 to 45 of 45
  1. #31
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Quote Originally Posted by Welshgasman View Post
    Show what you are passing in.


    Plus learn to walk your code with F8 and breakpoints.
    I am passing the fields [txtFoodItem] - strText; [txtSearch] - strSearch into the function.
    Function: HighTest (strText As String, strSearch As String)

    [txtFoodItem] is the records, [txtSearch] is the searchbox

    The formula on the form text object is:

    =IIf(IsNull([txtSearch]), [txtFoodItem],HighTest([txtFoodItem],[txtSearch])

  2. #32
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    See what @cj_london advised.
    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

  3. #33
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Quote Originally Posted by CJ_London View Post
    just realised this is the onchange event - so the control will not have been updated, You need to use strSearch.text
    Interesting. Did not know that. Where would you place that in the VBA? I keep getting the "Invalid Qualifier Error" when I add ".text" to strSearch.

    Thank you for helping me.

  4. #34
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    What happens now is the function runs when text is entered in the search box, but no results appear. (And there is a #Type error in the last record). Do we think this code is a viable solution? I'm open to anything.

  5. #35
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    Quote Originally Posted by Pianopizza5 View Post
    What happens now is the function runs when text is entered in the search box, but no results appear. (And there is a #Type error in the last record). Do we think this code is a viable solution? I'm open to anything.
    Well you have to assign the result of that function back to your control?
    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

  6. #36
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Got it! (at the moment)

    Needed to set HighTest = strTest.

  7. #37
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Thank you all!

    Now does anyone have any thoughts on why I can't add spaces in my search box? Since the event is On Current, the cursor resets after every stroke. I tried using Sel, but that doesn't account for spaces.

  8. #38
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    see again you db, you can add space to the search.
    Attached Files Attached Files

  9. #39
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    One more quick follow-up, in order for the highlight formula to work, I have to set the property Form – Data – Allow Additions to “Yes” (otherwise, the reference error appears (run-time 2185) when searching for an item). The main problem with this is that “!Type#” appears in the field that contains the formula in the “new record” at the bottom.

    I thought this might be because of the null value in the “new record”, so I inserted the Nz formula. I also tried adding default values for the new records, but didn’t have any luck.

    Here is the current formula in the control source:

    Code:
    =IIf(IsNull([txtSearch]),[txtFoodItem],HighTest([txtFoodItem],[txtSearch])

    And the Highest function is:

    Code:
    Function HighTest(strText As String, strSearch As String)
     
    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>")
     
    HighTest = strText
     
    End Function
    Any thoughts? Thanks.

  10. #40
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    I can get the highlight not hightest to work even with Additions = No?
    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

  11. #41
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Interesting, glad it worked for you. I’m not having any luck though. If the additions is set to “No,” the error comes up when you are searching for an item that is not in the records. It has to deal with there being no records (since the txtsearch is being used to filter the query).

  12. #42
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    Ah, you never said when nothing was found.
    So I just tried for something that is not there. Still no error?
    Do not know what to say?
    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

  13. #43
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    No worries. Thanks for trying.

    I attached my db to show you/whoever else sees this. It currently has the Form - Add Additions set to "No." The error appears when you search for an item that is not in the list. For example, type "ag."

    The error goes away by setting "Add Additions" to "Yes." But, then we get the "#Type!" result in the new record, which I don't want.SearchNoAddError.accdb.zip

  14. #44
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,563
    Well as I said, it does NOT do that for me, so hard to debug?
    Would be interested to see if it happens for anyone else who decides to try it.
    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

  15. #45
    Pianopizza5 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2019
    Posts
    46
    Very interesting! I looked into it more and the default value doesn't carry over when there is a formula and multiple tables in the query. I'm going to start a new thread because my original question was solved.

    Thank you for you help.

Page 3 of 3 FirstFirst 123
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