How format text string as Rich Text in VBA code

Posted on 2014-07-28
Last Modified: 2014-07-30
Thanks to an expert last week the following code concatenates strings into one text field.  Is there a way to make it Rich Text?

Dim strFruits as string

  strFruits = ""

  If Me.chkBox1 = True then
     strFruits = strFruits "OR Apple"
 End If

  If Me.chkBox2 = True then
     strFruits = strFruits "OR Orange"
 End If

 ' rem and so on
 ' Then

 ' Strip off the first OR
 If strFruits<>"" then
   strFruits = Mid$(strFruits,4)
   strMessage = "The fruits available are " & strFruits & " for you"
   strMessage "No fruits for you"
 End If 

Open in new window

Question by:SteveL13
LVL 24

Expert Comment

ID: 40225704
Rich text implies some format. Do you have any particular format in mind, i.e. make Apple bold and OR italic?
Or you just want to display it in a Rich Text control. If the latter than you do not need to do anything. Just assign it to the RichText control on your for and it will be displayed without any problems, like this:
Me!RichText1.Text = strFruits

Open in new window

LVL 13

Assisted Solution

by:Russell Fox
Russell Fox earned 166 total points
ID: 40225719
If you're going to display it in a rich textbox, you can use some html tags:
<div>			define some settings for a section of text
<em>			font-size in em's
<font>			define the font to use between <font></font>
<ol>			numbered list ("ordered")
	<li>		list item
<strong>		bold
<u>				underline
<ul>			bulleted list ("unordered")
	<li>		list item

Open in new window

LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 167 total points
ID: 40225868
In MS Access 2007 and higher "Rich Text" is really just HTML.

So you can format your string like this:

    ...strFruits will be BOLD

    ...strFruits will be UNDERLINED


But like the prior experts have stated, you don't just "Make" text Rich Text.

You simply add the HTML formatting tags and display the text in a textbox.
Be sure to use a textbox with its "TEXT FORMAT" property set to: Rich Text.

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

LVL 84
ID: 40226310
In MS Access 2007 and higher "Rich Text" is really just HTML.
"Rich Text" can be the standard .rtf format as well, but I agree with the others that you should use HTML when doing this. RTF is challenging, to say the least, to create. It's tag based, but the way the tags nest and interact with each other is insanely difficult, and it's quite easy to break the whole structure with a misplaced RTF tag. Unless you really need the high-level formatting of RTF (and if you do, you probably shouldn't be using Access for that) then just stick to HTML.

Author Comment

ID: 40226469
I didn't explain this well enough.  What I meant is that I want to be able to highlight part of the text that is in the concatenated block of text and bold just the highlighted portion, or underscore, or italics.  I can do this with a "normal" text field but can't seem to do so with a concatenated text field.
LVL 84

Accepted Solution

Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 167 total points
ID: 40226527
You can do this with any String value, so I'm not sure what you're asking. For example, using your code above:

 ' Strip off the first OR
 If strFruits<>"" then
   strFruits = Mid$(strFruits,4)
   strMessage = "The fruits available are <b>" & strFruits & "</b> for you"
   strMessage "<u>No fruits for you</u>"
 End If

The above changes would show in BOLD the text contained in your strFruits variable. It would also underline the "No Fruits for you" text.

Jeff has shown you how to make portions of your text Bold (i.e. use the <b></b> tags), and Russell has shown you several different HTML tags you can use. There are many HTML references around the internet that will show you all the tags available (although you should generally stick with the basics, like Bold or Underline).
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40227764

I just popped in here to lend a hand.
Scott and the prior experts have set you on the correct path...

No points for me...


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now