Solved

How format text string as Rich Text in VBA code

Posted on 2014-07-28
7
7,804 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 24

Expert Comment

by:chaau
Comment Utility
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 166 total points
Comment Utility
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 167 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 84
Comment Utility
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
Comment Utility
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 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 167 total points
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

771 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

7 Experts available now in Live!

Get 1:1 Help Now