How do I prevent Growing Line Spacing in RichTextBox Control

I have two RichTextbox controls on a MS-Access form.When I moved data from one control to another, extra \par markers are inserted.  This action is not consistent among several machines, even when the versions of RichTx32.ock, Riched20.dll and Riched32.dll are in the same versions.
Specifically, in this simple statemnt is where the trouble occurs:
Public Sub SetBody(TextRTF As String, ImageString As String)
       
    R.TextRTF = TextRTF                                    '(RP) set the RTF..

TextRtf a string with the following contents

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par Yours Truly,entMD]
\par
\par
\par
\par }

Notice that there are \par tokens between the first two printable lines.  The target control, R is a Richtx32.ocx ActiveX control.  Upon execution of this single statement, the contents of R.TextRTF are now 5 \par tokens between the first two printable lines.  In addition, another extra \par token has been added at the end.

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par Yours Truly,entMD]
\par
\par
\par
\par
\par }

What is going on here and how can I prevent it.  Note also that upon research, the data streams are slightly different on the working machines, but only in the \Generator token.  On a machine where extra tokens are bein inserted, it is:

{\*\generator Riched20 5.50.99.2050;}

On a machine where there are no extra tokens being inserted, it is:

{\*\generator Riched20 5.50.30.2002;}\

If this is a version-related problem, how do I version level.  I have tried changing versions of Richtx32.ocx, Riched20.dll and riched32.dll, all to no avail.  The problem occurrs on Vista, Win/Xp and Win2k machines.  ON onther machine with the same OS, it does not occur.

one other thing I noticed that might be helpful.  In environments where the extra token is inserted, a CRLF(Asc(13) & Asc(10) moved into the text component results in two \par tokens being generated in the rtf.  In the non-failing environments, that sequence result in only 1 \par being generate.

RickHoltAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rheitzmanCommented:
RichTextBoxes as a constant hassle when used with Access. If you can avoid them I'd suggest you do.

One trick to make things easier is to create an object that will work with the VBE Intellisense:

    Dim rtb As RichTextBox
    Set rtb = Me.R

Doing this will expose some to the hidden methods and properties of the control and make you life easier.

For example you can extract the text only (with line ends) from a Rich box:

   sText = rtb.Text

You can then assign the sText to another RichTextBox. You will loose formating of fonts but the text and line ends survives.

Sloshing the RTF between boxes using an external file sometimes works.

Don't expect RichTextBoxes to work on a Tab control. If you have to do that bind the control at the last moment (when the tab is made active.)

Expect weird problems.... Like a while back an automatic update changed something about the way line ends were encoded into RTF....

Hopefully there is something in the post that helps....


0
rheitzmanCommented:
You might try stripping out an CrLf pairs that may be in the RTF string

R.TextRTF = Replace(TextRTF, vbCrLf)

You might need to filter for just a single vbCr or vbLf.
0
RickHoltAuthor Commented:
Unfortunately, the application would need to be rewritten to remove reliance on rich Text box controls.  I will try the method you mention just in case it exposes some kind of method or parameter that I have not seen in my extensive web searches and will respond if I find anything fruitful.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

danaseamanCommented:
This is what I use for API created RichEdit to prevent extra vbCrLF(/par).
Please try this an let me know if it fixes the issue.

Private Const WM_USER = &H400
Private Const EM_SETEDITSTYLE = WM_USER + 204
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
SendMessage RichTextBox1.hWnd, EM_SETEDITSTYLE, 1&, 1&

Open in new window

0
danaseamanCommented:
Update

Private Const WM_USER = &H400
Private Const EM_SETEDITSTYLE = WM_USER + 204
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
SendMessageLong RichTextBox1.hWnd, EM_SETEDITSTYLE, 1&, 1&

Open in new window

0
RickHoltAuthor Commented:
I tried to take this advice, but it did not seem to operate without the flaws cited.  That
is, the SendMessage appears to have no effect.  Below is the code sequence and the result.  
Keep in mind that R and R2 are RichTextBox ActiveX controls on an MS-Access form called
Correspondence_Editor.

First, the setup for the SendMessage API Call.  This is in the Declarations section of the form.

Private Const WM_USER = &H400
Private Const EM_SETEDITSTYLE = WM_USER + 204
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


I am executing the exact same codein the Correspondence_editor form shown in the initial report with the exeception of the SendMessageLong, so we have the following:

    SendMessageLong Me!R.hWnd, EM_SETEDITSTYLE, 1&, 1&
    R.TextRTF = TextRTF                                    '(RP) set the RTF..

Before the executionof the SendMessage, the contents of TextRtf are as follows:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par
\par
\par
\par }

The return code of the SendMessageLong is 0

After execution of the R.TextRTF = TextRTF, the contents of R.TextRTF is:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par
\par
\par
\par
\par }

Despite the SendMessage, The same additional \par was added after the first text line, after the second text line and after the \pard.  Therefore, I conclude that the suggested solution does not work.  Perhaps I missed something?
[btw, I tried to respond individually to suggested soultions, but clicking onthe No box is causing Errors on the we page.]
0
RickHoltAuthor Commented:
Upon further experimentation, this seems to be due to flaws in the Richtx32.ocx itself.  I have used instead a third party replacement control, Chado SpellEditor control, that does exhibit the problem noted in this problem description.  Though there are probably others, this one uses all the same property, method and object names as the Richtx32.ocx does and seems to behave the sam in all windows environmets.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.