INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Can you format different parts of a text box

Can you format different parts of a text box

(OP)
I have Acccess 2007 and a text box on a report with the code

CODE

=([ProductName] & " @ " & [ApplicationRate] & [ApplicationUnits]) 

Is it possible to have [Productname] as one colour, font size and bold and [ApplicationRate] & [ApplicationUnits] as a different colour font and non bold, without having separate text boxes?

RE: Can you format different parts of a text box

Yes, you must first go to the text box property and change the text type from plain text to rich text. Then when you concatenate your string you have to also add in HTML tags. To learn the tags I cheat. I build a simple unbound text box on a form and set it to rich text. Then I format the string using the formatting tools. I have a button on the form that then has
Debug.print txtbox.value
The tags will have some double quotes that you will have to replace with single quotes.

RE: Can you format different parts of a text box


Quote (MajP)

I cheat. I build a simple unbound text box on a form and set it to rich text. Then I format the string using the formatting tools. I have a button on the form that then has
Debug.print txtbox.value
The tags will have some double quotes that you will have to replace with single quotes.

Wow! Some Major cheating going on here! Well I sure hope that this germinates into a Colonel of truth that flowers into General reality. Nice Tip!

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Can you format different parts of a text box

When I get time I will make a faq

Create a very simple form "RichTextHelper"
Add large input text box (rich text) and a large output text box (plain text). Add a command button to get the codes "cmdGetCodes".
here is the code

CODE

Private Sub Form_Load()
  'You can do this in design view, but in case you forget
  Me.txtBxInput.TextFormat = acTextFormatHTMLRichText
  Me.txtBxOutput.TextFormat = acTextFormatPlain
End Sub
Private Sub cmdGetCodes_Click()
  Me.txtBxOutput.Value = Me.txtBxInput.Value
  'Since you need to convert the single quotes most of the time to use
  Me.txtBxOutput.Value = Replace(Me.txtBxOutput.Value, """", "'")
End Sub 

so in the input text box I typed this string
Bold Text and Red Text
I bolded the "Bold Text" and made the "Red Text" font red.
I click the button and in the output box I get the string

<div><strong>Bold Text</strong> and <font color=#ED1C24>Red Text</font></div>

To make this easier to understand here it is with some carriange return
<div>
<strong>
Bold Text
</strong> and
<font color=#ED1C24>
Red Text
</font>
</div>

notice that "bold text" is wrapped in the strong tag, and "red text" is wrapped in the font color tag. "and" is outside of any tags.

So to go in reverse, here is an example of code.
Add another command button "cmdTest"

CODE

Private Sub cmdTest_Click()
 UseTags
End Sub

Public Sub UseTags()
  Dim strOne As String
  Dim strTwo As String
  strOne = "Bold Text"
  strTwo = "Red Text"
  Me.txtBxInput.Value = "<strong>" & strOne & "</strong>" & " and "
  Me.txtBxInput.Value = Me.txtBxInput.Value & "<font color=#ED1C24>" & strTwo & "</font>"
  'need to surround with div
  Me.txtBxInput.Value = "<div>" & Me.txtBxInput.Value & "</div>"
  Me.txtBxOutput.Value = Me.txtBxInput.Value
End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close