Solved

How format text string as Rich Text in VBA code

Posted on 2014-07-28
7
9,167 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
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 166 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 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:

<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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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.
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 84

Accepted Solution

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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