Convert string to RTF-formatted OLE object field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an Access app that is exporting data to a DB2 database via ODBC. I
must use the contents of a text field in my app to populate an RTF-formatted
OLE object field in the DB2 database as part of append query. When I just map
the field directly, the DB2 field gets only the first character of the text
field.

Is there a way to "wrap" the output of my string so that it will appear as
RTF and populate the field correctly? The DB2 gurus' explanation was that it
needs to be "cast as a blob" (that's a lot of help to me in Access, now,
isn't it?)
 
You can easily prepend the required RTF header string and the required
closing Brace. Here's a previous post of mine on a related issue.
http://groups.google.ca/group/micro...q=lebans+rtf+}&rnum=13&hl=en#3446dace11b9fd7e


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.
 
Back
Top