Changing the text/highlight color in a bound textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sphinney
    New Member
    • Mar 2007
    • 69

    Changing the text/highlight color in a bound textbox

    I have a datasheet style form with textbox (MyTextBox) that has the Text Format property set to "Rich Text". It is bound to a memo field in a table. How do I change the text or highlight color of certain text in the textbox such that the formating is saved in an underlying memo field?

    My situation is a little different than other posts I read. Most posts show how to find and select certain text in a textbox, and then change the formating of the control (textbox). Since the form is a datasheet style form, changing the formating of the control will change the formating for that field in all records! I want to change the formating of the text IN the textbox so that the formating is captured in the memo field for an individual record. Make sense?

    I've figured out how to find the records, fields, and text that I want to modify, but I'm missing the line of code that modifies text formating. Here's a sample of what I have:

    Code:
    Me.MyTextBox.SetFocus
    Me.MyTextBox.SetFocus.SelStart = 0
    Me.MyTextBox.SetFocus.SelLength = Len(MyRichTextBox.Value)
    What comes next? I've searched through all of the DoCmd.RunComman d's and I can't find one that changes the text color or highlight color.

    Any help is greatly appreciated.
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Hello Sphinney,

    When you say a datasheet view are you talking about a subform?

    What is your criteria to determine the change in colour of the memo field?

    Do you actually want the Memo field to save the colour codes permanently or just appear to change colours on the form? (I could do either for you)

    Is this Access 2007?

    cheers,

    Originally posted by sphinney
    I have a datasheet style form with textbox (MyTextBox) that has the Text Format property set to "Rich Text". It is bound to a memo field in a table. How do I change the text or highlight color of certain text in the textbox such that the formating is saved in an underlying memo field?

    My situation is a little different than other posts I read. Most posts show how to find and select certain text in a textbox, and then change the formating of the control (textbox). Since the form is a datasheet style form, changing the formating of the control will change the formating for that field in all records! I want to change the formating of the text IN the textbox so that the formating is captured in the memo field for an individual record. Make sense?

    I've figured out how to find the records, fields, and text that I want to modify, but I'm missing the line of code that modifies text formating. Here's a sample of what I have:

    Code:
    Me.MyTextBox.SetFocus
    Me.MyTextBox.SetFocus.SelStart = 0
    Me.MyTextBox.SetFocus.SelLength = Len(MyRichTextBox.Value)
    What comes next? I've searched through all of the DoCmd.RunComman d's and I can't find one that changes the text color or highlight color.

    Any help is greatly appreciated.

    Comment

    • sphinney
      New Member
      • Mar 2007
      • 69

      #3
      Hi mshmyob,

      Thanks for replying to my post. My form is a subform with the Default View property set to "Datasheet" (no other views are allowed). The form only contains a few textboxes that are bound to memo fields in "MyTable". The textboxes have the Text Format property set to "Rich Text". This is an Access 2007 database (i.e. *.accdb).

      I did not include information about criteria in my original post because I thought it was extemporaneous to my primary question and I didn't want to burden folks with unnecessary details. But in answer to your question (at least partly) my application reads text out of a Microsoft Word 2007 file. It then looks for matching text in the memo fields in MyTable.

      If matching text is found in MyTable, I want to permanently change the text and background color in the memo field (and not just temporarily display it). I couldn't figure out how to modify the formating of the text by accessing the memo fields in MyTable directly via a DAO recordset. So, instead, I bound the memo fields to textboxes on a form and am trying to modifiy the text and background color in the textboxes, then update MyTable.

      It seems like it should be so easy.
      1. Set focus to a particular textbox
      2. Set the selection start position (based on the text I'm looking for)
      3. Set the selection length (based on the text I'm looking for)
      4. Change the text/background color
      5. Update the data back to MyTable

      I just can't figure out the VB code for item 4.

      Thanks for your help!

      Originally posted by mshmyob
      Hello Sphinney,

      When you say a datasheet view are you talking about a subform?

      What is your criteria to determine the change in colour of the memo field?

      Do you actually want the Memo field to save the colour codes permanently or just appear to change colours on the form? (I could do either for you)

      Is this Access 2007?

      cheers,

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        OK I will see what I can throw together for you in the morning. Just got home and pretty tired now.

        cheers,

        Originally posted by sphinney
        Hi mshmyob,

        Thanks for replying to my post. My form is a subform with the Default View property set to "Datasheet" (no other views are allowed). The form only contains a few textboxes that are bound to memo fields in "MyTable". The textboxes have the Text Format property set to "Rich Text". This is an Access 2007 database (i.e. *.accdb).

        I did not include information about criteria in my original post because I thought it was extemporaneous to my primary question and I didn't want to burden folks with unnecessary details. But in answer to your question (at least partly) my application reads text out of a Microsoft Word 2007 file. It then looks for matching text in the memo fields in MyTable.

        If matching text is found in MyTable, I want to permanently change the text and background color in the memo field (and not just temporarily display it). I couldn't figure out how to modify the formating of the text by accessing the memo fields in MyTable directly via a DAO recordset. So, instead, I bound the memo fields to textboxes on a form and am trying to modifiy the text and background color in the textboxes, then update MyTable.

        It seems like it should be so easy.
        1. Set focus to a particular textbox
        2. Set the selection start position (based on the text I'm looking for)
        3. Set the selection length (based on the text I'm looking for)
        4. Change the text/background color
        5. Update the data back to MyTable

        I just can't figure out the VB code for item 4.

        Thanks for your help!

        Comment

        • sphinney
          New Member
          • Mar 2007
          • 69

          #5
          No problem. I'm just appreciative of any assistance/guidance your able to give.

          Originally posted by mshmyob
          OK I will see what I can throw together for you in the morning. Just got home and pretty tired now.

          cheers,

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            Sorry for the delay but have been very busy.

            Here is a demo to try. See if this helpss and is of any use to you. Let me know and I can answer any questions or make any changes.

            It demonstrates how to search for a string and replace it and then update the memo field using HTML coding and displays it in a subform datasheet view. This works only in AC2007 since it uses the new RTF properties of fields/controls.


            cheers,
            Attached Files

            Comment

            • sphinney
              New Member
              • Mar 2007
              • 69

              #7
              mshmyob,

              Thanks for the sample file & code! I was successfully able to use the <font color =...> tag to change the font color. I also included a <p style="backgrou nd-color:.."> tag to alter the highlight color (as it turns out, one must use the font tag first before the paragraph tag).

              You helped me do exactly what I wanted to do! I'm most greateful. On my own I was headed down an entirely different (and wrong) path.

              Many thanks,

              Originally posted by mshmyob
              Sorry for the delay but have been very busy.

              Here is a demo to try. See if this helpss and is of any use to you. Let me know and I can answer any questions or make any changes.

              It demonstrates how to search for a string and replace it and then update the memo field using HTML coding and displays it in a subform datasheet view. This works only in AC2007 since it uses the new RTF properties of fields/controls.


              cheers,

              Comment

              • mshmyob
                Recognized Expert Contributor
                • Jan 2008
                • 903

                #8
                You're welcome sphinney - good luck with your project.

                cheers,

                Originally posted by sphinney
                mshmyob,

                Thanks for the sample file & code! I was successfully able to use the <font color =...> tag to change the font color. I also included a <p style="backgrou nd-color:.."> tag to alter the highlight color (as it turns out, one must use the font tag first before the paragraph tag).

                You helped me do exactly what I wanted to do! I'm most greateful. On my own I was headed down an entirely different (and wrong) path.

                Many thanks,

                Comment

                Working...