RTFcontrol of memo fields

C

carbra

Access VBA code:
I have created a RTFcontrol box (ActiveX) ref.
(http://www.lebans.com/richtext.htm) by Stephen Leban
It is working nicely. - but:
Now I have to copy (insert codes) data from my memo field so it can be shown
in the RTFcontrol box.
If I use cut and page (CTRL-C and V) to the RTFcontrol box the text will be
shown correctly, but it will take too long time to
do it in 7000 records.
So I try to make a code for inserting the RTF2 control code in every record.

Dim txtIn As String
Dim txtOut As String
txtIn =
"{\rtf1\ansi\ansicpg1252\deff0\deflang1030{\fonttbl{\f0\fnil\fcharset0
Arial;}} {\colortbl ;\red0\green0\blue0;} {\*\generator Riched20
5.50.99.2009;}\viewkind4\uc1\pard\cf1\fs18"
txtOut = "\par}"
Me.note = txtIn & Me.note & txtOut
Me.note.Requery

It is working but the text is without line feed (vbCRLF). It is missing the
"\par" code.

???: How can I by code make a cut/page from the memo field to the RTF
control.
Have anyone a suggestion??

Thanks in advance
carbra
 
S

Stephen Lebans

A quick search via GoogleGRoups yielded the following post:

Do you currently have RTF formatted text in the Memo field? The RTF2 control
displays formatted/encoded RTF text....not plain text.
I have posted code in the past few months to add the required RTF encoding
to existing plain text fields.

From: Stephen Lebans - view profile
Date: Thurs, Mar 23 2006 12:38 am
Email: "Stephen Lebans"
<[email protected]>
Groups: comp.databases.ms-access, microsoft.public.access.forms
Not yet ratedRating:
show options


Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author


The RTF control can only display RTF encoded text. If you want to simply
display plain text then wrap your plain text within the required RTF
encoding.


Here's a previous post of mine on a related issue.
http://groups.google.ca/group/microsoft.public.access.forms/browse_fr...


From: Stephen Lebans - view profile
Date: Tues, Feb 14 2006 9:30 pm
Email: "Stephen Lebans"
<[email protected]>
Groups: microsoft.public.access.forms
Not yet ratedRating:
show options


Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse | Find messages by this author


Let me know how you make out.


Make sure your Form has:
A TextBox control named txtComment bound to the Comment field(just o you can
see the RTF encoding)
an RTF2 control bound to the Comment field
A CommandButton named cmdRTF


In your References, make sure the ref to DAO is higher in the list than ADO.


Place this code behind the Command Button.


Private Sub CmdRTF_Click()
On Error GoTo Err_CmdRTF_Click


Dim sRTFdata As String
Dim sHeader As String
Dim sText As String


sHeader =
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0
Arial;}}"
sHeader = sHeader & "{\colortbl
;\red0\green0\blue0;}\viewkind4\uc1\pard\cf1\fs24"


' I could have shortened the code but I wanted you(and others I refer to
this posting) to see what is happening at every step.


With Me.RecordsetClone
' Move to first record
.MoveFirst


' Loop until all records are processed
' This example uses a field named "Comment"
' Note this is the name of the FIELD not the
' name of the TextBox control bound to this field
Do While Not .EOF
.Edit
sText = IIf(IsNull(.Fields("Comment")), "", .Fields("Comment"))
' See if field is empty
If Len(sText & vbNullString) = 0 Then
sRTFdata = sHeader & "}"
Else
sRTFdata = sHeader & sText & "\par }"
End If


' Save our RTF encoded string back to Comment field
.Fields("Comment") = sRTFdata
.Update
' Move to next record
.MoveNext
Loop


End With


Exit_CmdRTF_Click:
Exit Sub


Err_CmdRTF_Click:
MsgBox Err.Description
Resume Exit_CmdRTF_Click


End Sub


--



--

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

carbra

Thanks Leban,
The code is working nicely when using new note fields but:
The suggested code will handle then comment as a long string and only
setteing the "\par" for vbCrLf in the end of the string. So if the comment
is broken by new lines before copy, it will not be copied to the RTF2 control
box with CrLf.
To make it more clear, e.g.:

the txtComment box include then following text:
"This is line one
This is line two
and this is line three"

The RTF2 control box will appear with this single line:
"This is line oneThis is line twoand this is line three"

question: How can I set in a "\par"-string in the txtComment box for each
CrLf (not shown in the txtComment field). And why is the cut/paste working
correctly when the code for CrLf is not shown. I have more than 10.000
comment fields to copy to the RTF2 control field, so it will take too long
time with the cut/paste method. I hope somebody can clear this op for me.
 
S

Stephen Lebans

You are trying to merge Text into an RTF encoded stream of characters. They
are two different entities and cannot by freely mixed.

To simply the issue, why not do a search and replace on the vbCrLf and
replace it with "\par".

There is no need to manually Copy or Paste.

--

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

carbra

Thanks Stephen,

It sound simply but then code vbCrLf is not included in the string - so no
match doing search. When I write the following code in the cmdRTF button:
MsgBox "the string is: " & Me.RTFcontrol & vbCrLf & Me.note
The message box displace:
"{\rtf1\ansi\ansicpg1252\deff0\deflang1030{\fonttbl{\f0\fnil\fcharset0
Arial;}}
{\colortbl ;\red0\green0\blue0;}
{\*\generator Riched20 5.50.99.2009;}\viewkind4\uc1\pard\cf1\fs18
This is line one
This is line two
And this i line three
\par}" for both strings.
But the output in the RTFcontrol field shows:
"This is line oneThis is line twoAnd this i line three"
The code for CrLf is NOT shown in the string. Is it because it is a HTML
code behind the table field??? Please guide me here. I can not search for
vbCrLf when it is not included in the string, and so, I cannot replace with
"\par". I only need to solve this, for me houge problem, before my program is
running perfectly.
Question: how to search and replace for the code vbCrLf with "\par" in a
note field when not shown in the string??
I can email you my RTFcontrol.mdb-file (248kb) so you can see then
functionality or put it on an official web site to download (security
reason). It is the test-file.
 
C

carbra

The missing code for CrLf changing to \par. Please fee free to download the
test mdb-file from http://www.dsmg.suite.dk/ under "Nyttige links" find the
link: "RTFcontrol". If you can brake the puzzle on how to convert all txt
from the Note field to the RTFcontrol field for ALL records, please write you
code in this NG.
 

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