Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Vic[_2_] Vic[_2_] is offline
external usenet poster
 
Posts: 18
Default RTF Mail Merge Fields

Hello,

I am trying to setup a mail merge and use rtf text fields from a database.
These rtf fields contain the formatting instructions for bolding, bullets,
font settings etc. However, the problem I am having is word does not
recognize these formatting characters and prints everything as plain text.
My main document is an rtf file.

How can I get word to interpretate these instructions? I am using Word 2002.


Thank you,

Vic


  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default RTF Mail Merge Fields

Hi Vic,

Word's mailmerge facility outputs the source data as displayed, but without any character formatting that may be present in the data
source.

You can, however, apply formatting switches (picture switches in Word parlance) to mergefields to control the output's appearance.

--
Cheers
macropod
[MVP - Microsoft Word]


"Vic" wrote in message ...
Hello,

I am trying to setup a mail merge and use rtf text fields from a database. These rtf fields contain the formatting instructions
for bolding, bullets, font settings etc. However, the problem I am having is word does not recognize these formatting characters
and prints everything as plain text. My main document is an rtf file.

How can I get word to interpretate these instructions? I am using Word 2002.


Thank you,

Vic



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP on news.microsoft.com Doug Robbins - Word MVP on news.microsoft.com is offline
external usenet poster
 
Posts: 407
Default RTF Mail Merge Fields

For any more than the formatting that can be applied by use of Word field
formatting switches, I think that you would have to use a "roll-your-own"
equivalent to mailmerge where in place of a mail merge main document
containing mergefields, you would use a template containing docvariable
fields and then you would run a macro that would create a new document from
that template for each record in data source, setting the values of
variables in the document to the value of corresponding field for that
record in the data source and making use of the formatting information in
the data source to apply the required formatting.

For information on Word field formatting switches, see "Formatting Word
fields with switches" on fellow MVP Graham Mayor's website at:

http://www.gmayor.com/formatting_word_fields.htm


--
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, originally posted via msnews.microsoft.com

"Vic" wrote in message
...
Hello,

I am trying to setup a mail merge and use rtf text fields from a database.
These rtf fields contain the formatting instructions for bolding, bullets,
font settings etc. However, the problem I am having is word does not
recognize these formatting characters and prints everything as plain text.
My main document is an rtf file.

How can I get word to interpretate these instructions? I am using Word
2002.


Thank you,

Vic




  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Vic[_2_] Vic[_2_] is offline
external usenet poster
 
Posts: 18
Default RTF Mail Merge Fields

Doug,

Thanks for the reply but I'm having a problem understanding how to implement
these switches. The rtf fields are inserted in an Access database using a
VB program and contain data such as:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fc harset0 MS Sans
Serif;}{\f1\fnil\fcharset2 Symbol;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 OK - We need to change these text boxes
so that we can \b set strings of words to BOLD\b0 , change fonts, do
underlines and we also need to do bullets:
\par
\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnin dent0{\pntxtb\'B7}}Oranges
\par {\pntext\f1\'B7\tab}Apples
\par {\pntext\f1\'B7\tab}Pears
\par \pard
\par This all seems to work but when it gets merged into word, all of the
formatting characters show as text!
\par
\par
\par }

It appears to me from the use of these switches I can use /*charformat to
bold, underline and italics. So where are these switches implemented? I
tried as a test to press ctl F9 and inserted Graham's bold example { REF
chapter2_title \* Charformat } would display "Whales of the Pacific" but it
only displayed this as plain text without formatting.

I need to be able to have this done programmatically so I would assume I'd
need some sort of word macro. The VB program invokes the mail merge and
turns the document into a PDF which then gets merged with other PDF
documents to produce a final document as a PDF. So I suppose I'd have to
invoke the word macro to massage the word document after the mail merge is
completed. Would that be correct?

I don't see that bullets, indenting and font changes are supported with
switches. Are there any examples of using templates with docvariable
fields. There are about 20 merge fields that are inserted in this document.

Would you provide a bit of guidance on where to go from here? Are there
some examples somewhere for doing this. It would seem to me to be a quite
common occurance but I'm finding limited information on using switches and
merge fields that contain rtf data.

Vic






"Doug Robbins - Word MVP on news.microsoft.com"
wrote in message ...
For any more than the formatting that can be applied by use of Word field
formatting switches, I think that you would have to use a "roll-your-own"
equivalent to mailmerge where in place of a mail merge main document
containing mergefields, you would use a template containing docvariable
fields and then you would run a macro that would create a new document
from that template for each record in data source, setting the values of
variables in the document to the value of corresponding field for that
record in the data source and making use of the formatting information in
the data source to apply the required formatting.

For information on Word field formatting switches, see "Formatting Word
fields with switches" on fellow MVP Graham Mayor's website at:

http://www.gmayor.com/formatting_word_fields.htm


--
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, originally posted via msnews.microsoft.com

"Vic" wrote in message
...
Hello,

I am trying to setup a mail merge and use rtf text fields from a
database. These rtf fields contain the formatting instructions for
bolding, bullets, font settings etc. However, the problem I am having is
word does not recognize these formatting characters and prints everything
as plain text. My main document is an rtf file.

How can I get word to interpretate these instructions? I am using Word
2002.


Thank you,

Vic





  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default RTF Mail Merge Fields

The problem with trying to include RTF text via merge fields is that
merge fields only insert character data, with no formatting information
from the data source. If you copied your Access data to a Word document,
used that as the data source, and used REF fields instead of MERGEFIELD
fields to insert data, some of the formatting gets through, but it's all
rather arbitrary.

The only way I know to get the RTF text from Access to Word that has any
hope of working is to export the contents of each Access RTF field to a
..rtf file on disk, then insert t using an INCLUDETEXT field. This is of
course non-trivial, but I quote an earlier message that has some ideas...

----------------------
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?
----------------------

Of course, that assumes that you are using the MailMerge mechanism, but
faced with this problem for real, I would probably avoid MailMerge and
use Access VBA code to generate each Word document in turn (assuming
you're not going for a catalog/directory), saving each RTF field to disk
as needed and inserting it directly using the relevant Word Insert
file method. However, I cannot provide you with code for that.

Yes, it probably is something that lots of people want to do, but there
are non-trivial problems to solve when attempting this, no matter how
you encode your formatted text (e.g., you encode it using XML, but using
which vocabulary/ies?). And I don't suppose anyone on the development
side has wanted to solve it for RTF-encoded text ever since RTF became a
"legacy format", which you could argue is over a decade ago.

Peter Jamieson

http://tips.pjmsn.me.uk

Vic wrote:
Doug,

Thanks for the reply but I'm having a problem understanding how to
implement these switches. The rtf fields are inserted in an Access
database using a VB program and contain data such as:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fc harset0 MS Sans
Serif;}{\f1\fnil\fcharset2 Symbol;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 OK - We need to change these text
boxes so that we can \b set strings of words to BOLD\b0 , change fonts,
do underlines and we also need to do bullets:
\par
\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnin dent0{\pntxtb\'B7}}Oranges

\par {\pntext\f1\'B7\tab}Apples
\par {\pntext\f1\'B7\tab}Pears
\par \pard
\par This all seems to work but when it gets merged into word, all of
the formatting characters show as text!
\par
\par
\par }

It appears to me from the use of these switches I can use /*charformat
to bold, underline and italics. So where are these switches
implemented? I tried as a test to press ctl F9 and inserted Graham's
bold example { REF chapter2_title \* Charformat } would display "Whales
of the Pacific" but it only displayed this as plain text without
formatting.

I need to be able to have this done programmatically so I would assume
I'd need some sort of word macro. The VB program invokes the mail merge
and turns the document into a PDF which then gets merged with other PDF
documents to produce a final document as a PDF. So I suppose I'd have to
invoke the word macro to massage the word document after the mail merge
is completed. Would that be correct?

I don't see that bullets, indenting and font changes are supported with
switches. Are there any examples of using templates with docvariable
fields. There are about 20 merge fields that are inserted in this
document.

Would you provide a bit of guidance on where to go from here? Are there
some examples somewhere for doing this. It would seem to me to be a
quite common occurance but I'm finding limited information on using
switches and merge fields that contain rtf data.

Vic






"Doug Robbins - Word MVP on news.microsoft.com"
wrote in message ...
For any more than the formatting that can be applied by use of Word
field formatting switches, I think that you would have to use a
"roll-your-own" equivalent to mailmerge where in place of a mail merge
main document containing mergefields, you would use a template
containing docvariable fields and then you would run a macro that
would create a new document from that template for each record in data
source, setting the values of variables in the document to the value
of corresponding field for that record in the data source and making
use of the formatting information in the data source to apply the
required formatting.

For information on Word field formatting switches, see "Formatting
Word fields with switches" on fellow MVP Graham Mayor's website at:

http://www.gmayor.com/formatting_word_fields.htm


--
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, originally posted via msnews.microsoft.com

"Vic" wrote in message
...
Hello,

I am trying to setup a mail merge and use rtf text fields from a
database. These rtf fields contain the formatting instructions for
bolding, bullets, font settings etc. However, the problem I am
having is word does not recognize these formatting characters and
prints everything as plain text. My main document is an rtf file.

How can I get word to interpretate these instructions? I am using
Word 2002.


Thank you,

Vic







  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Vic[_2_] Vic[_2_] is offline
external usenet poster
 
Posts: 18
Default RTF Mail Merge Fields

Peter,

Thanks for the reply! I found an old post where you had indicated using
tables and the originator had indicated success. I have modified my program
to create the merge data source as a word table and I'm having some
successes. I load the form(s) containing the rtf data and then create a
word document with a table for the merge data which I then copy and paste
into the word table columns from the form values. It works! I had to
change MERGEFIELD to Ref to make it work.

The only problem I'm having now setting the bullet style. When it gets
merged the bullets come in as 1 - 2 - 3 ...


Thanks Peter, Your help is appreciated.


Vic





"Peter Jamieson" wrote in message
...
The problem with trying to include RTF text via merge fields is that merge
fields only insert character data, with no formatting information from the
data source. If you copied your Access data to a Word document, used that
as the data source, and used REF fields instead of MERGEFIELD fields to
insert data, some of the formatting gets through, but it's all rather
arbitrary.

The only way I know to get the RTF text from Access to Word that has any
hope of working is to export the contents of each Access RTF field to a
.rtf file on disk, then insert t using an INCLUDETEXT field. This is of
course non-trivial, but I quote an earlier message that has some ideas...

----------------------
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?
----------------------

Of course, that assumes that you are using the MailMerge mechanism, but
faced with this problem for real, I would probably avoid MailMerge and use
Access VBA code to generate each Word document in turn (assuming you're
not going for a catalog/directory), saving each RTF field to disk as
needed and inserting it directly using the relevant Word Insert file
method. However, I cannot provide you with code for that.

Yes, it probably is something that lots of people want to do, but there
are non-trivial problems to solve when attempting this, no matter how you
encode your formatted text (e.g., you encode it using XML, but using which
vocabulary/ies?). And I don't suppose anyone on the development side has
wanted to solve it for RTF-encoded text ever since RTF became a "legacy
format", which you could argue is over a decade ago.

Peter Jamieson

http://tips.pjmsn.me.uk

Vic wrote:
Doug,

Thanks for the reply but I'm having a problem understanding how to
implement these switches. The rtf fields are inserted in an Access
database using a VB program and contain data such as:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fc harset0 MS Sans
Serif;}{\f1\fnil\fcharset2 Symbol;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 OK - We need to change these text
boxes so that we can \b set strings of words to BOLD\b0 , change fonts,
do underlines and we also need to do bullets:
\par
\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnin dent0{\pntxtb\'B7}}Oranges
\par {\pntext\f1\'B7\tab}Apples
\par {\pntext\f1\'B7\tab}Pears
\par \pard
\par This all seems to work but when it gets merged into word, all of the
formatting characters show as text!
\par
\par
\par }

It appears to me from the use of these switches I can use /*charformat to
bold, underline and italics. So where are these switches implemented? I
tried as a test to press ctl F9 and inserted Graham's bold example { REF
chapter2_title \* Charformat } would display "Whales of the Pacific" but
it only displayed this as plain text without formatting.

I need to be able to have this done programmatically so I would assume
I'd need some sort of word macro. The VB program invokes the mail merge
and turns the document into a PDF which then gets merged with other PDF
documents to produce a final document as a PDF. So I suppose I'd have to
invoke the word macro to massage the word document after the mail merge
is completed. Would that be correct?

I don't see that bullets, indenting and font changes are supported with
switches. Are there any examples of using templates with docvariable
fields. There are about 20 merge fields that are inserted in this
document.

Would you provide a bit of guidance on where to go from here? Are there
some examples somewhere for doing this. It would seem to me to be a
quite common occurance but I'm finding limited information on using
switches and merge fields that contain rtf data.

Vic






"Doug Robbins - Word MVP on news.microsoft.com"
wrote in message ...
For any more than the formatting that can be applied by use of Word
field formatting switches, I think that you would have to use a
"roll-your-own" equivalent to mailmerge where in place of a mail merge
main document containing mergefields, you would use a template
containing docvariable fields and then you would run a macro that would
create a new document from that template for each record in data source,
setting the values of variables in the document to the value of
corresponding field for that record in the data source and making use of
the formatting information in the data source to apply the required
formatting.

For information on Word field formatting switches, see "Formatting Word
fields with switches" on fellow MVP Graham Mayor's website at:

http://www.gmayor.com/formatting_word_fields.htm


--
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, originally posted via msnews.microsoft.com

"Vic" wrote in message
...
Hello,

I am trying to setup a mail merge and use rtf text fields from a
database. These rtf fields contain the formatting instructions for
bolding, bullets, font settings etc. However, the problem I am having
is word does not recognize these formatting characters and prints
everything as plain text. My main document is an rtf file.

How can I get word to interpretate these instructions? I am using Word
2002.


Thank you,

Vic






  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Vic[_2_] Vic[_2_] is offline
external usenet poster
 
Posts: 18
Default RTF Mail Merge Fields

Another thing the bullets cause is to change the paragraph numbering that
follows the bulleted list i.e.

(The following data is from the merge source)
Text Box Facility Info: OK - We need to change these text boxes so that we
can set strings of words to
BOLD, change fonts, do underlines and we also need to do bullets:
This all seems to work but when it gets merged into word, all of the
formatting is lost. No bolding, underlines,
bullets etc.

1. Apples
2. Oranges
3. Bananas
This seems to be changing the paragraph number in the rest ot the document

(the main document starts here)
INTRODUCTION
3.1. PURPOSE


The 3.1 PURPOSE should be 1.1. After the merge it became 3.1. Perhaps if I
could get the bullet character to change to something else may have some
sort of impact on the numbering but so far I haven't found a way to specify
the bullet character.


Vic



"Peter Jamieson" wrote in message
...
The problem with trying to include RTF text via merge fields is that merge
fields only insert character data, with no formatting information from the
data source. If you copied your Access data to a Word document, used that
as the data source, and used REF fields instead of MERGEFIELD fields to
insert data, some of the formatting gets through, but it's all rather
arbitrary.

The only way I know to get the RTF text from Access to Word that has any
hope of working is to export the contents of each Access RTF field to a
.rtf file on disk, then insert t using an INCLUDETEXT field. This is of
course non-trivial, but I quote an earlier message that has some ideas...

----------------------
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?
----------------------

Of course, that assumes that you are using the MailMerge mechanism, but
faced with this problem for real, I would probably avoid MailMerge and use
Access VBA code to generate each Word document in turn (assuming you're
not going for a catalog/directory), saving each RTF field to disk as
needed and inserting it directly using the relevant Word Insert file
method. However, I cannot provide you with code for that.

Yes, it probably is something that lots of people want to do, but there
are non-trivial problems to solve when attempting this, no matter how you
encode your formatted text (e.g., you encode it using XML, but using which
vocabulary/ies?). And I don't suppose anyone on the development side has
wanted to solve it for RTF-encoded text ever since RTF became a "legacy
format", which you could argue is over a decade ago.

Peter Jamieson

http://tips.pjmsn.me.uk

Vic wrote:
Doug,

Thanks for the reply but I'm having a problem understanding how to
implement these switches. The rtf fields are inserted in an Access
database using a VB program and contain data such as:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fc harset0 MS Sans
Serif;}{\f1\fnil\fcharset2 Symbol;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 OK - We need to change these text
boxes so that we can \b set strings of words to BOLD\b0 , change fonts,
do underlines and we also need to do bullets:
\par
\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnin dent0{\pntxtb\'B7}}Oranges
\par {\pntext\f1\'B7\tab}Apples
\par {\pntext\f1\'B7\tab}Pears
\par \pard
\par This all seems to work but when it gets merged into word, all of the
formatting characters show as text!
\par
\par
\par }

It appears to me from the use of these switches I can use /*charformat to
bold, underline and italics. So where are these switches implemented? I
tried as a test to press ctl F9 and inserted Graham's bold example { REF
chapter2_title \* Charformat } would display "Whales of the Pacific" but
it only displayed this as plain text without formatting.

I need to be able to have this done programmatically so I would assume
I'd need some sort of word macro. The VB program invokes the mail merge
and turns the document into a PDF which then gets merged with other PDF
documents to produce a final document as a PDF. So I suppose I'd have to
invoke the word macro to massage the word document after the mail merge
is completed. Would that be correct?

I don't see that bullets, indenting and font changes are supported with
switches. Are there any examples of using templates with docvariable
fields. There are about 20 merge fields that are inserted in this
document.

Would you provide a bit of guidance on where to go from here? Are there
some examples somewhere for doing this. It would seem to me to be a
quite common occurance but I'm finding limited information on using
switches and merge fields that contain rtf data.

Vic






"Doug Robbins - Word MVP on news.microsoft.com"
wrote in message ...
For any more than the formatting that can be applied by use of Word
field formatting switches, I think that you would have to use a
"roll-your-own" equivalent to mailmerge where in place of a mail merge
main document containing mergefields, you would use a template
containing docvariable fields and then you would run a macro that would
create a new document from that template for each record in data source,
setting the values of variables in the document to the value of
corresponding field for that record in the data source and making use of
the formatting information in the data source to apply the required
formatting.

For information on Word field formatting switches, see "Formatting Word
fields with switches" on fellow MVP Graham Mayor's website at:

http://www.gmayor.com/formatting_word_fields.htm


--
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, originally posted via msnews.microsoft.com

"Vic" wrote in message
...
Hello,

I am trying to setup a mail merge and use rtf text fields from a
database. These rtf fields contain the formatting instructions for
bolding, bullets, font settings etc. However, the problem I am having
is word does not recognize these formatting characters and prints
everything as plain text. My main document is an rtf file.

How can I get word to interpretate these instructions? I am using Word
2002.


Thank you,

Vic






  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default RTF Mail Merge Fields

Ypur best bet here is probably to avoid using automatic numbering in the
main document - although it may be possible to prevent "interference"
between the numbering in the RTF and the numbering in the main document
by specifying a named list template or some such in the main document,
that stuff is hard to tame. What you coud try is SEQ-based numbering in
the main document, e.g. where you use

{ SEQ } fields, the \r switch to reset numbering for each sequence, \h
to hide the result when you do that, and the \c switch to re-use the
existing number, e.g.

{ SEQ level2 \r0 \h }{ SEQ level1 }.
{ SEQ level1 \c }.{ SEQ level2 }
{ SEQ level1 \c }.{ SEQ level2 }
{ SEQ level1 \c }.{ SEQ level2 }

{ SEQ level2 \r0 \h }{ SEQ level1 }.
{ SEQ level1 \c }.{ SEQ level2 }
{ SEQ level1 \c }.{ SEQ level2 }
{ SEQ level1 \c }.{ SEQ level2 }

to give you a sequence like

1.
1.1
1.2
1.3

2.
2.1
2.2
2.3

I don't know if that approach fits your requirement, but it's the best I
can do right now.

Peter Jamieson

http://tips.pjmsn.me.uk

Vic wrote:
Another thing the bullets cause is to change the paragraph numbering
that follows the bulleted list i.e.

(The following data is from the merge source)
Text Box Facility Info: OK - We need to change these text boxes so that
we can set strings of words to
BOLD, change fonts, do underlines and we also need to do bullets:
This all seems to work but when it gets merged into word, all of the
formatting is lost. No bolding, underlines,
bullets etc.

1. Apples
2. Oranges
3. Bananas
This seems to be changing the paragraph number in the rest ot the document

(the main document starts here)
INTRODUCTION
3.1. PURPOSE


The 3.1 PURPOSE should be 1.1. After the merge it became 3.1. Perhaps
if I could get the bullet character to change to something else may have
some sort of impact on the numbering but so far I haven't found a way to
specify the bullet character.


Vic



"Peter Jamieson" wrote in message
...
The problem with trying to include RTF text via merge fields is that
merge fields only insert character data, with no formatting
information from the data source. If you copied your Access data to a
Word document, used that as the data source, and used REF fields
instead of MERGEFIELD fields to insert data, some of the formatting
gets through, but it's all rather arbitrary.

The only way I know to get the RTF text from Access to Word that has
any hope of working is to export the contents of each Access RTF field
to a .rtf file on disk, then insert t using an INCLUDETEXT field. This
is of course non-trivial, but I quote an earlier message that has some
ideas...

----------------------
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?
----------------------

Of course, that assumes that you are using the MailMerge mechanism,
but faced with this problem for real, I would probably avoid MailMerge
and use Access VBA code to generate each Word document in turn
(assuming you're not going for a catalog/directory), saving each RTF
field to disk as needed and inserting it directly using the relevant
Word Insert file method. However, I cannot provide you with code for
that.

Yes, it probably is something that lots of people want to do, but
there are non-trivial problems to solve when attempting this, no
matter how you encode your formatted text (e.g., you encode it using
XML, but using which vocabulary/ies?). And I don't suppose anyone on
the development side has wanted to solve it for RTF-encoded text ever
since RTF became a "legacy format", which you could argue is over a
decade ago.

Peter Jamieson

http://tips.pjmsn.me.uk

Vic wrote:
Doug,

Thanks for the reply but I'm having a problem understanding how to
implement these switches. The rtf fields are inserted in an Access
database using a VB program and contain data such as:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fc harset0 MS Sans
Serif;}{\f1\fnil\fcharset2 Symbol;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 OK - We need to change these
text boxes so that we can \b set strings of words to BOLD\b0 , change
fonts, do underlines and we also need to do bullets:
\par
\par
\pard{\pntext\f1\'B7\tab}{\*\pn\pnlvlblt\pnf1\pnin dent0{\pntxtb\'B7}}Oranges
\par {\pntext\f1\'B7\tab}Apples
\par {\pntext\f1\'B7\tab}Pears
\par \pard
\par This all seems to work but when it gets merged into word, all of
the formatting characters show as text!
\par
\par
\par }

It appears to me from the use of these switches I can use
/*charformat to bold, underline and italics. So where are these
switches implemented? I tried as a test to press ctl F9 and inserted
Graham's bold example { REF chapter2_title \* Charformat } would
display "Whales of the Pacific" but it only displayed this as plain
text without formatting.

I need to be able to have this done programmatically so I would
assume I'd need some sort of word macro. The VB program invokes the
mail merge and turns the document into a PDF which then gets merged
with other PDF documents to produce a final document as a PDF. So I
suppose I'd have to invoke the word macro to massage the word
document after the mail merge is completed. Would that be correct?

I don't see that bullets, indenting and font changes are supported
with switches. Are there any examples of using templates with
docvariable fields. There are about 20 merge fields that are
inserted in this document.

Would you provide a bit of guidance on where to go from here? Are
there some examples somewhere for doing this. It would seem to me to
be a quite common occurance but I'm finding limited information on
using switches and merge fields that contain rtf data.

Vic






"Doug Robbins - Word MVP on news.microsoft.com"
wrote in message
...
For any more than the formatting that can be applied by use of Word
field formatting switches, I think that you would have to use a
"roll-your-own" equivalent to mailmerge where in place of a mail
merge main document containing mergefields, you would use a template
containing docvariable fields and then you would run a macro that
would create a new document from that template for each record in
data source, setting the values of variables in the document to the
value of corresponding field for that record in the data source and
making use of the formatting information in the data source to apply
the required formatting.

For information on Word field formatting switches, see "Formatting
Word fields with switches" on fellow MVP Graham Mayor's website at:

http://www.gmayor.com/formatting_word_fields.htm


--
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, originally posted via msnews.microsoft.com

"Vic" wrote in message
...
Hello,

I am trying to setup a mail merge and use rtf text fields from a
database. These rtf fields contain the formatting instructions for
bolding, bullets, font settings etc. However, the problem I am
having is word does not recognize these formatting characters and
prints everything as plain text. My main document is an rtf file.

How can I get word to interpretate these instructions? I am using
Word 2002.


Thank you,

Vic






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2007 Mail Merge Labels skips fields using update fields Dianne Griffin Mailmerge 3 August 8th 08 03:59 PM
Using if fields in mail merge to ignore empty fields Larry S. Mailmerge 9 August 15th 06 08:10 AM
MS Word form fields versus mail merge fields [email protected] Mailmerge 4 March 4th 06 05:31 PM
Form fields versus mail merge fields [email protected] Microsoft Word Help 2 February 16th 06 02:12 PM
mail merge some fields leave other as form fields BethW Mailmerge 1 September 20th 05 06:47 PM


All times are GMT +1. The time now is 03:55 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"