Mail Merge Format Text String

P

Peter Hibbs

I am using Access 2003 to create a mail merge document using
Automation. For reasons too complicated to explain here I have a Memo
field (plus a number of other fields) in an Access table which will be
the source data for the mail merge. The Memo field will contain
between one and 20 lines of text.

What I would like is to have the ability to add some rudimentary
formatting to the various lines of text in this field. The problem is
that, at the moment, any formatting done to the field affects all the
text in the field - all bold, all italics, etc. What I need is to
allow the user to enter some sort of control code in the text which
would then enable/disable formatting.

For example, if I had something like this in the Memo field :-

This is normal text this is bold this is normal.

then Word would change the character sequence into the equivalent
of ^B and show the text between them in bold. I don't need anything
more fancy then that, bold, italics and underline would suffice.

Is there any way to add some sort of If-Then-Else control codes in the
mail merge field which could check the string and apply the
appropriate formatting.

Peter Hibbs.
 
M

macropod

Hi Peter,

What you're asking can't be done that way. If you need parts of your text to have different formatting, those parts need to be in
separate fields in your data source. Alternatively, if you add suitable tags to your data field (as it seems you're prepared to do),
you could use a macro after running the merge to find the tags, remove them and re-format the intervening text as desired.
 
P

Peter Hibbs

Hi macropod,

I had suspected as much. I will look into your suggestion about
formatting after the merge, it may be possible to do this from Access
using Automation (I am more comfortable writing VBA code than Macros),
also I am trying to make things as easy for the end user as possible,
i.e. avoid them having to add a Macro to each new Word document they
create.

Anyway, thanks again for your thoughts.

Peter Hibbs.
 
P

Peter Hibbs

Hi macropod and Peter,

Yes, I am aware that, in Word, a Macro IS VBA, in the past I have
created a Macro and then looked at the VBA it created. What I really
meant was that I am more familiar with Access VBA than all the Word
commands and functions (although I have used the mail merge commands,
of course, in my Access code that creates the mail merge documents).

Anyway, back to the problem in hand. Having thought about it some
more I think it would be quite tricky using Automation code from
within Access to process the mail merge document that Word creates, I
assume it creates it in memory somewhere until the user saves it to
disk.

I quite like the idea of creating a Word macro that could just scan
through the document and change the formatting between two embedded
characters that the user would not normally use in a document. As I
said before, I need to make it as easy as possible for the user so I
would like to avoid having them create the same macro every time they
make up a new mail merge document.

Is it possible, therefore, to create a template file which holds the
macro and then let them use the template to start a new mail merge
document. And perhaps they could have a new button/icon which they
could click on to run the macro once they have created the mail merge
document. Would the template macro and button be automatically copied
into the new mail merge document each time.

The other possiblity would be to add a macro to the Normal.dot file
but I don't really want this facility on every document they create,
only mail merge documents.

I haven't had time to try any of this yet but if you think it will
work I will have a go.

Thanks for any info.

Peter Hibbs.
 
D

Doug Robbins - Word MVP on news.microsoft.com

The mail merge main document can certainly be saved as a template and if the
macro, to perform the task of replacing the text within a couple of
formatting marks with formatted text, is stored in that template, it would
be available for use on any document created from the template. It would
however be necessary for the mail merge main document to remain open for the
macros in that template to be available for use on the document created by
execution of the mail merge.

An alternative of course would be to use the mailmerge events that are
available and incorporate the code to do the formatting into some code that
would run as the mailmerge is executed. For an example of the use of those
events, see the add-in for creating individual letters from a mail merge
main document that you can down load from fellow MVP Graham Mayor's website
at:

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

I have to admit however, I am wondering whether what you are wanting to do
is not easier to do with an Access report.

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

Peter Hibbs

Doug,

I will look into using templates with an embedded macro to make the
formatting changes after the mail merge letter has been created.

Thanks for the Web site, that looks very interesting, I will need to
study it further and I will pass the URL on to my client.

As I mentioned in an earlier post, I am writing this database for a
client and they will only have a .mde file so they will not be able to
make any changes to any reports I supply. Doing this via Word has the
big advantage that they can design their letters exactly how they want
(and there could be dozens) whereas I would have to make any changes
they want to any reports.

I will see how I get on with the template idea and will come back with
more questions if I need to, thanks again for your help.

Peter Hibbs.
 

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