Concatenated text and Leban's Rich Text Control

M

milkmoney1970

Greetings All,

I was wondering if anyone has run across the problem I'm having with
concatenating rtf control contents and line returns.

I am using Steven Leban's rich text tool in Access 2007 (as
Microsoft's integrated rich text control is pretty much useless if you
need to manipulate its contents) (Steven's tool is excellent). I am
trying to insert new text into the middle of a rich text field, after
formating it as needed, however, I've noticed that the rich text box
inserts a line return at the end of my inserted text.

I have searched around and have read that rich text sometimes works
this way, but was wondering if there is a way of removing or avoid
having, a line return inserted after my text.

Any guidance would be appreciated.
 
S

Stephen Lebans

Post your code you are using to insert the text into the existing string.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
M

milkmoney1970

Thanks Stephen for taking the time to look at this.

Private Sub cmd_Add_Click()
Dim iStart As Integer
Dim strColor As String
Dim strBegin As String
Dim strEnd As String
Dim rtfAdd As RTF2
Dim rtfEdit As RTF2

On Error GoTo ErrorHandler 'Set error handler routine
Set rtfAdd = Me!rtf_Add.Object 'Set object for rtf add control
Set rtfEdit = Forms!frm_EditReview!rtf_Edit.Object 'Set object for
rtf edit control
iStart = rtfEdit.SelStart 'Get the start of selected text rich text
control
rtfAdd.PlainText = " " & rtfAdd.PlainText & " "
rtfAdd.SelStart = 0 'Set start mouse position
rtfAdd.SelLength = Len(rtfAdd.RTFtext) 'Set end mouse position
strColor = Forms!frm_Review!txt_Color 'Get the users color
Select Case strColor 'Set color for user's comments
Case "<font color=red>"
rtfAdd.SelColor (vbRed)
Case "<font color=blue>"
rtfAdd.SelColor (vbBlue)
Case "<font color=green>"
rtfAdd.SelColor (vbGreen)
Case "<font color=orange>"
rtfAdd.SelColor (vbOrange)
Case "<font color=purple>"
rtfAdd.SelColor (vbPurple)
Case "<font color=brown>"
rtfAdd.SelColor (vbBrown)
Case "<font color=black>"
rtfAdd.SelColor (vbRed)
End Select
rtfEdit.SelStart = iStart
rtfEdit.SelTextRTF = RemovePar(rtfAdd.SelTextRTF)
DoCmd.Close acForm, "frm_AddInfo" 'Close form
ExitHere:
Exit Sub
ErrorHandler:
dhError ("cmd_Add_Click")
Resume ExitHere
End Sub

Private Sub Form_Load()
Dim rtfAdd As RTF2
Dim rtfEdit As RTF2
Dim fnt As New StdFont
'On Error GoTo ErrorHandler
Set rtfAdd = Me!rtf_Add.Object 'Set objects for rtf add control
Set rtfEdit = Forms!frm_EditReview!rtf_Edit.Object 'Set objects for
rtf edit control
rtfAdd.RTFtext = "" 'Clean out rtf add field
With fnt
.Name = "calibri"
.Size = 11
End With
Set rtfAdd.Font = fnt
Me!rtf_Add.SetFocus
ExitHere:
Exit Sub
ErrorHandler:
dhError ("Form_Load")
Resume ExitHere
End Sub
 
S

Stephen Lebans

Tried to get to this sooner but I have company for the Easter weekend.

First thing, you should not mix modifying the control's contents via
PlainText and RTFtext. Stick with RTFtext.

I cannot remember seeing that a line return is added to the end of inserted
text. Let's have a peek at my source code:

void CRTF2Ctrl::SetSelTextRTF(LPCTSTR lpszNewValue)
{
long l;

// Set our nSize global
nSize = (strlen(lpszNewValue)) ;
if (nSize == 0)
{
// DO NOTHING
return ;
}

BufIndex = 0;
// Insert formatted RTF text into the control
EDITSTREAM es;
es.dwError = 0;
es.pfnCallback = mEditStreamCallback;
es.dwCookie = (DWORD) lpszNewValue;

// REPLACE NOT CLEAR CONTENTS
l = ::SendMessage(m_hWnd, EM_STREAMIN, (WPARAM) SF_RTF | SFF_SELECTION,
(LPARAM) &es);
SetModifiedFlag();
}


I'm not adding a line return when I insert the RTF text.

Couple of questions:
1) Have you confirmed this behaviour, of the addition of a line return for
RTF text inserted via the SelTextRTF method, into a blank control?

2) So do I understand correctly that you have resolved your issue by calling
your RemovePar function?


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
M

milkmoney1970

Hi Stephen,

So sorry to have you hard at work on a family holiday. I can certainly
wait a few days so please don't take time from your guests.

I will attempt to confirm the suggestion #1 you made below and let you
know what I find.

As for fixing the problem, yes, I have creative a tentative solution
(after posting my question) by striping out the \par that gets
inserted during the concatenation. I only use this routine when I
don't want a line return after my inserted text. I wanted to check
with you to make sure that I wasn't stripping out rich text coding
when I shouldn't be. I'm not the most experienced programmer, so I
thought that writing a routine to do this might be overkill.

Just as a follow up question. I'm need to create a format that
indicates that something has been deleted from the text, without
actually removing the text. I was hoping to use a strikethrough. I
looked through the RTF2 library and didn't see a method for the
strikethrough of selected text. Is there one that I missed, or do you
know of any way to simulate one using your control?

Thanks again for your help. I will get back to you on the question
above.
 
M

milkmoney1970

Hi Stephen,

I tried, as you suggested, a simplified example using a rich text
control and by avoiding mixing plaintext and rtftext I have fixed the
problem I was experiencing. Now I will just have to see if I can make
it work in my code, which I'm sure I can now do. Thanks.

If you have a chance, at some point, to answer my question
re:strikethrough in my last reply, that would be great.
 
S

Stephen Lebans

I think Strikethrough is a function of the Font properties of the selected
text.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
M

milkmoney1970

I thought that may be I could apply a standard font to the selected
text and use a strikethrough, but doing this affects the whole text
not just the selected text. I looked through all of the selected text
properties and although there are great properties (bold, italics,
indent, superscript,subscript, etc) I couldn't find a way to apply a
strikethrough. If you get a moment can you expand a little on your
thought below. I'm sorry if I'm missing something.
 
M

milkmoney1970

Hi Stephen,

Problem solved. All I had to do is copy the section of text that I
want to delete, set the temporary temp rtf control to a stdfont with
the strikethrough property set to true. And then copy this back into
its original location in the original rtf control.

I was looking at the release date on your control and it seems that it
was written quite some time ago. Interesting, even though Microsoft
Access has been through several incarnations, since your control came
out, they have failed to provide even a fraction of the versatility
found in your control.

Thanks for your help and patience. A very useful tool.
 
B

Brossyg

Stephen,

I asked another mvp, but do you have simplied step-by-step instructions on
your site as to how to implement your rtf control? I went to your site and
connot figure it out.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top