469,125 Members | 1,709 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,125 developers. It's quick & easy.

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:

Expand|Select|Wrap|Line Numbers
  1. Me.MyTextBox.SetFocus
  2. Me.MyTextBox.SetFocus.SelStart = 0
  3. Me.MyTextBox.SetFocus.SelLength = Len(MyRichTextBox.Value)
What comes next? I've searched through all of the DoCmd.RunCommand's and I can't find one that changes the text color or highlight color.

Any help is greatly appreciated.
Jun 19 '09 #1
7 14059
mshmyob
904 Expert 512MB
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,

@sphinney
Jun 22 '09 #2
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!

@mshmyob
Jun 22 '09 #3
mshmyob
904 Expert 512MB
OK I will see what I can throw together for you in the morning. Just got home and pretty tired now.

cheers,

@sphinney
Jun 23 '09 #4
No problem. I'm just appreciative of any assistance/guidance your able to give.

@mshmyob
Jun 23 '09 #5
mshmyob
904 Expert 512MB
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
File Type: zip rtf_demo.zip (110.9 KB, 1129 views)
Jun 24 '09 #6
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="background-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,

@mshmyob
Jun 26 '09 #7
mshmyob
904 Expert 512MB
You're welcome sphinney - good luck with your project.

cheers,

@sphinney
Jun 26 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Charles A. Lackman | last post: by
7 posts views Thread by Howard Minor | last post: by
1 post views Thread by John | last post: by
14 posts views Thread by > Adrian | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.