Lebans Richtext Control

G

Gary O

I have installed the control and bound it to a field in my database.

This field contains data input prior to installing the Richtext control.

Is it possible to display this data with the Richtext control?

In my testing any data not in Richtext format does not display, any new data
entered using the Richtext control does display.

Is there any tips/tricks to be able to display both old and new data in the
same field of my form?
 
S

Stephen Lebans

The RTF2 control is made to display RTF formatted Text. The field you want
to bind to the RTF2 control already contains plain text(not RTF). All you
need to do is prepend a valid RTF header string on the front of the
exisiting text and then at the end add a closing Brace Char"}".

Create a new record and save it without adding any text.
Copy and paste this record as PLAIN text into Wordpad or Notepad.
Use this string and an update query to add the RTF header text in front of
your existing data and closing char "}" at the end of the existing data.

There are several threads you could find on GoogleGroups in the Access NG's
that detail this issue as other users have obviously experienced what you
are going through.

If after you find the relevant threads(s) you still need help just post back
here with your work so far.
Try searching the Access NG's with GoogleGroups with keywords like:
RTF2 Update query
--

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

Gary O

Stephen,

Searching google groups I received the following results:
Searched all groups Results 1 - 6 of 6 for RTF2 Update query (0.12
seconds )
Unfortunately none of the six provided any assistance.

Being very VB illeterate I am unsure how to create an update query which
will add the RFT beginning and ending codes.

Any assistance would be much appreciated.

Gary O
 
S

Stephen Lebans

The code/logic was in the second thread returned from your GoogleGroups
search.

'Add rtf format to raw text
var3 = "{\rtf\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans
Serif;}}{\colortbl ;\red112\green112\blue255;}\viewkind4\uc1\pard" & var3 &
"}"
'Send to RTF2 Control
Me.RTFControl1.RTFText = var3


Since you new to programming I will walk you through this.
Create a form(if you have not already) for data entry that is bound to the
Table you want to update. The field that currently contains the plaint Text
that you want to convert to RTF text must be of type MEMO not TEXT.
Insert the RTF2 ActiveX control onto the form and set its ControlSource to
the field that currently contains the plain Text you want to convert to RTF.

Now I need to know:
1) The version of Access you are using
2) The name of the FIELD(not the name of the control) that contains the
plain text you want to convert to RTF.
3) What do you want for a Font and Font Size for all of the records we will
convert to RTF.

Finally, all of the records must contain plain text for this routine to
work.

--

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

Gary O

Hi Stephen,

Thanks for your help - it is greatly appreciated.

You wanted to know:
1) The version of Access you are using - Access 2002
2) The name of the FIELD(not the name of the control) that contains the
plain text you want to convert to RTF. - "comment"
3) What do you want for a Font and Font Size for all of the records we will
convert to RTF. - My current report using this form outputs the text as
"Arial 12"

When enetering data into the comments field I have been entering carriage
returns - will these be picked up? If not, it doesn't matter as it is
unlikely that they will need to be reprinted.

Regards

Gary O
 
S

Stephen Lebans

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.
 

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