Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How format text string as Rich Text in VBA code

Posted on 2014-07-28
7
Medium Priority
?
11,221 Views
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"
 Else
   strMessage "No fruits for you"
 End If 

Open in new window

0
Comment
Question by:SteveL13
7 Comments
 
LVL 25

Expert Comment

by:chaau
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

0
 
LVL 13

Assisted Solution

by:Russell Fox
Russell Fox earned 664 total points
ID: 40225719
If you're going to display it in a rich textbox, you can use some html tags:
<blockquote>
<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

1
 
LVL 74

Assisted Solution

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

So you can format your string like this:

<b>strFruits</b>
    ...strFruits will be BOLD

<u>strFruits</u>
    ...strFruits will be UNDERLINED

....etc

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.

JeffCoachman
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 85
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.
0
 

Author Comment

by:SteveL13
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.
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 668 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"
 Else
   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).
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40227764
SteveL13,

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...
;-)

JeffCoachman
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…
Suggested Courses

782 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