Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Unanswered: Highlight certain text in a text box

    Here's an interesting thing I was requested to do and I'm wondering if anyone else has done something like this (so I don't need to try and reinvent the wheel)

    I have a "keyword" unbound text search box on a form. I have it so that after the "keyword" is entered, the query for the form requeries with criteria: like * & Forms!MainForm!MySearchBoxName & *.

    What I would like to do (if possible) is highlight the wording in the bound field text box with what is entered in the unbound keyword search box. Has anyone ever done anything like this?
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Hi, Paul,

    Do you mean, as in

    Code:
    Me.MyTextBoxName = Me.MySearchBoxName.Value
    Me.MyTextboxName.FontWeight = 700
    Sam

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Thanks for the reply Sam! I'll give it a try and let you know.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Sam,

    Here's the problem:

    Me.MyTextBoxName = Me.MySearchBoxName.Value
    (this erases the value of bound field (ie. MyTextBoxName). I need it to retain the entire bound field value and highlight just the portion of the text which matches the keyword search.)

    Me.MyTextboxName.FontWeight = 700
    (this will highlight everything - again, I need just the portion the bound text field that matches the keyword highlighted.)

    I hope I've explained it better as to what I need. Maybe I misunderstood your solution.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    Wouldn't you need to iterate through the textbox for me.mySearchBox.value?

    ---------
    New thought!
    So take your text box that youre searching on, make it an array.

    if (me.textbox.value == me.searhbox.value){ me.textbox.[array].value.background =yellow}
    Ryan
    My Blog

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I'm not quite sure I follow you Ryan but I believe you're probably right in that I will need to walk-through characters in the text box (which is what I'm hoping to avoid as this would slow down the process of going from record to the next record.) I was hoping to possibly utilize the instr function and somehow just highlight that piece of wording in the text box. I'm not sure if I can utilize the .background property.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    Don't look at that sample code. I was just pulling it from the sky. But can you somehow parse each word into an array. Take that array, and compare it to the value of your textbox, if the two match, highlight that position of your array and continue on. (I am thinking of the highlight function of the Google Toolbar.)
    Ryan
    My Blog

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ok, I think an illustration will help to clarify the issue
    Paul searches for "Paul" and he want's the following results
    Code:
    Paul is a moderator at dbforums.com
    Stormy's owner is Paul
    Another Paul related sentence
    The problem I see with this is that a control only has one font colour property. I have yet to discover any different
    George
    Home | Blog

  9. #9
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    George,

    I was thinking that there might be a way I can highlight the text somehow (not change the color of it but highlight it as if I were to copy/cut a piece of the text - ie. you know - like holding down the left mouse button and dragging over a string of text). I never successfully found a way to change the color in a text box either but I think there might be a way to highlight a string of text.
    Last edited by pkstormy; 08-21-07 at 20:30.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  10. #10
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    p.s. Thanks for cleaning up for me George regarding the duplicate post on this. I didn't notice that this post got duplicated.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Dim SearchStr As String
    
     SearchStr = "Paul"
    
    If IsNull(Me.Text1.Value) Then
        Me.Text1.Value = "this is a test example for Paul Kohn"
        Me.Text1.SetFocus
        Me.Text1.SelStart = InStr(1, Me.Text1.Value, SearchStr) - 1
        Me.Text1.SelLength = Len(SearchStr)
    Else
        Me.Text1.Value = Null
    End If
    EDIT: Remember that focus has to be given to the control before you can use any of the Sel functions.
    So I reckon this can only be done for one field at a time - but I might be wrong!
    George
    Home | Blog

  12. #12
    Join Date
    Jun 2004
    Location
    Seattle, WA
    Posts
    601
    Wouldn't there be an issue with that kind of highlighting Paul? What if you search for "the"? Your text box has the following text:
    The bird flies in the sky.

    You cannot select both the's...
    Ryan
    My Blog

  13. #13
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Don't mean to rain on your parade, Paul, but it seems that all font/typeface characteristics affect only the entire control, not a word within the control. What you might do is have 3 unbound textboxes in the form, each one touching the other, with the middle one set to bold (in the property sheet). In VBA, then, you can assign the left textbox with the leading words in the field, the middle one with the search argument, and the right one with the trailing words.

    A bit tedious, obviously, but I don't know of any other way.

    Of course, Ryan does have a point...

    Sam

  14. #14
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    CardFile DB

    Thanks everyone for the input!! I'm going to do some experimenting (with George's code) and let you know. This is the last step I need to do for this database and if I can't highlight the search wording somehow, it's not life or death for this program. I thought I'd upload this in case anyone is interested (it has some neat coding which removes the MSAccess top menu - ie. you can't even tell it's Access as only the form shows, and I made it so the user's can select their own coloring scheme!)

    If you decide to try the program, first get into it holding down the shift key to add your windows user name to the dbo_THC_AdminTable table - I quickly converted it from SQL Server tables to Access tables and removed the confidential information so you can take a look at it if anyone's interested.) Please keep in mind that I made this within a couple of days so the code is not completely cleaned up and fully commented but again, it's worth a look just to see the setting of your own coloring. Once you've added your login to the dbo_THC_AdminTable, make sure to copy the default color values from the "ispak" record to your login record - it needs some default values for the color fields - I know I could have also done this easier but again, I only had a few days to work on it. Also make your security level = 2. After you've added your login information to the table, close and re-open the mdb to see how it works.

    I originally did the coloring schematic coding a few years ago, kept the code, and had a request for it in this program. I found that I will play with the program for an hour or so just picking out the color schemes that I like best.

    Lastly, you will probably need to remove this code: Call GetLinkedTables from the MainFormBackground form (this is the call to the function to automatically create the ODBC DSN for SQL Server tables.)

    Any feedback (Good or bad) is welcomed!
    Attached Files Attached Files
    Last edited by pkstormy; 08-22-07 at 14:50.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  15. #15
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You know what Sam - that was going to be my next suggestion
    I just didn't like the way it looked on a form in my head

    I loved playing with creating custom styles/attributes/favorites per user in a database once... I just took far too long playing with this than anything else!

    Good luck with it Paul - 100 points if you can come up with a working solution to this problem!
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •