Insert Access RTF fields with appropriate format

J

Juvenal León

Hello everybody,

I want to mail merge retrieving fields from an Access table which store RTF
text in memo fields. The merged file shows the raw information with the RTF
codes, like "{\rtf1\ansi\ansicpg1252\deff0{\fonttbl....}" The question is: Is
it possible to show the actual formatted RTF text instead of the RTF codes?

Thanks in advance.

jvleon
 
P

Peter Jamieson

Only if you save each memo to a file then use INCLUDETEXT to include it.

Peter Jamieson
 
S

solarin solaRIN

Hi peter , I am triying to sove the same issue could you please be a bit more explicit in your response, i would do appreciated it

thanks
 
D

Doug Robbins - Word MVP

It will make it easier for Peter and others to know what you are talking
about if you append this request to the original thread.

What does the "same issue" mean?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter Jamieson

Using Mailmerge without code, you have to export the content of each
field containing rtf text to a disk file, then use INCLUDETEXT to insert it.

Typically you would need to export the text to a filename that is
somehow related to a unique identifier (e.g. the primary key field(s))
in the table you are merging. So suppose you have a autonumber primary
key called k containing 1,2,3,... and your column is called mycolumn,
you might create a file called c:\myrtfs\mycolumn1.rtf for the rtf for
mycolumn in record 1

Then you would use a nested INCLUDETEXT field in your mail merge main
document, e.g.

{ INCLUDETEXT "c:\\myrtfs\\mycolumn{ MERGEFIELD k }" }

Alternatively, you might be able to use Word MailMerge events: for each
Access record, the event handler (probably MailMergeBeforeRecordMerge)
would need to use e.g. ADO to export the RTF, then insert it into the
document. I do not know how feasible that is.

I can't say I recommend this, but for a small number of records you
could consider the following:
a. create an Access User-defined (VBA) function that exports the RTF
for a specified field into a file
b. create an Access query that returns the other data you want and
calls that function. Ideally the function would return the pathname of
the file it created, with backslashes doubled up.
c. In Word, connect to that query using the DDE connection method
(there is another possibility)

Here's a how-to I wrote in 2001, slightly modified:


Suppose the function
is called rtfx
b. create a query that has columns k, r and rtfx
c. use the query as the datasource for your merge.

For example, the following Access function should do the necessary

Function rtfx(n As Integer, s As String) As String
dim r as String
Dim t As String * 1

' Generate the file name you want
rtfx = "c:\myrtfs\rtf" & Trim(Str(n)) & ".rtf"
' and return a doubled-backslash version ias the function result
rtfx = "c:\\myrtfs\\rtf" & Trim(Str(n)) & ".rtf"

Open r For Binary As 1 Len = 1
For i = 1 To Len(s)
t = Mid(s, i, 1)
Put #1, i, t
Next
Close 1

End Function

Then your query might have columns

k, r, and rtfx(k,r)

e.g.

Run the query in Access and Access will modify the text in column 3 to
something like
Expr1: rtfx([k],[r])

You can then change Expr1 to a more helpful name such as "filepath"

Then create your Word mailmerge main document and set up the query as the
data source - Word should offer k,r and filepath as the possible
mergefields.

Your INCLUDETEXT field would then need to look like

{ INCLUDETEXT "{ MERGEFIELD filepath }" }

Worth a try?


Peter Jamieson
http://tips.pjmsn.me.uk
 

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