A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Optional Merge Fields



 
 
Thread Tools Display Modes
  #1  
Old August 24th, 2004, 10:11 AM
Pete Bennett
external usenet poster
 
Posts: n/a
Default Optional Merge Fields

Hi,

I have a letter template (in Word 2000) that can optionally be used to
create a merge master letter (simply by inserting AutoText containing merge
fields). The mail merge operation is being handled entrirely by VBA by the
way.

This works fine, except I would now like to have the same template to have
the capability of handling two data sources (both CSV files). Many of the
fields will be the same, but one CSV file will have more fields than the
other.

Is there any way that I can use truely optional merge fields, as conditional
merge fields can only function if the merge fields are actually there. I
want to avoid (if at all possible) any messages about "this merge field
doesn't exist".

Thanks,
  #2  
Old August 24th, 2004, 04:41 PM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default

Hi =?Utf-8?B?UGV0ZSBCZW5uZXR0?=,

I don't think there's any way to do this as you envision; no way to "blank out"
unused merge fields. Two alternate approaches occur to me, right off hand:

1. Create both letters as AutoText entries. If the one data source is used,
insert that entry; if the other data source is used, the second entry. As each
autotext entry will contain the fields specific to the data source used, the
problem shouldn't occur.

2. Create both data sources with the same fields. Some of the fields will
always be empty (because they'll never be filled with data), but at least
they'll be present in the data source, so IF fields will work with them.

I have a letter template (in Word 2000) that can optionally be used to
create a merge master letter (simply by inserting AutoText containing merge
fields). The mail merge operation is being handled entrirely by VBA by the
way.

This works fine, except I would now like to have the same template to have
the capability of handling two data sources (both CSV files). Many of the
fields will be the same, but one CSV file will have more fields than the
other.

Is there any way that I can use truely optional merge fields, as conditional
merge fields can only function if the merge fields are actually there. I
want to avoid (if at all possible) any messages about "this merge field
doesn't exist".


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

  #3  
Old August 24th, 2004, 05:21 PM
Pete Bennett
external usenet poster
 
Posts: n/a
Default

Cindy,

I see what you're saying there and those solutions would work fine if I
could get the data source to be changed to a different format.

Since I'm using VBA, a more elagant solution is possible (after some head
scratching!)

What I can do is reconcile the merge fields in the data source against the
merge fields held in the master document before the merge is executed.

So, this will check the contents of
ActiveDocument.MailMerge.DataSource.FielNames against
ActiveDocument.MailMerge.Fields

And subsequently delete any merge fields fields in the master document that
aren't contained in the data source. I just have to make sure that I don't
mess up the contents of any conditional merge fields and invalidate them.
Luckily for me, the're not a player.

Ironically, the urgency for this has now passed and I won't have to deal
with it for the next four months, but thought you might find my solution of
interest. I've not tested it, but the theory seems sound to me.

Regards,

Pete.

"Cindy M -WordMVP-" wrote:

Hi =?Utf-8?B?UGV0ZSBCZW5uZXR0?=,

I don't think there's any way to do this as you envision; no way to "blank out"
unused merge fields. Two alternate approaches occur to me, right off hand:

1. Create both letters as AutoText entries. If the one data source is used,
insert that entry; if the other data source is used, the second entry. As each
autotext entry will contain the fields specific to the data source used, the
problem shouldn't occur.

2. Create both data sources with the same fields. Some of the fields will
always be empty (because they'll never be filled with data), but at least
they'll be present in the data source, so IF fields will work with them.

I have a letter template (in Word 2000) that can optionally be used to
create a merge master letter (simply by inserting AutoText containing merge
fields). The mail merge operation is being handled entrirely by VBA by the
way.

This works fine, except I would now like to have the same template to have
the capability of handling two data sources (both CSV files). Many of the
fields will be the same, but one CSV file will have more fields than the
other.

Is there any way that I can use truely optional merge fields, as conditional
merge fields can only function if the merge fields are actually there. I
want to avoid (if at all possible) any messages about "this merge field
doesn't exist".


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)


  #4  
Old August 25th, 2004, 09:55 AM
Cindy M -WordMVP-
external usenet poster
 
Posts: n/a
Default

Hi =?Utf-8?B?UGV0ZSBCZW5uZXR0?=,

What I can do is reconcile the merge fields in the data source against the
merge fields held in the master document before the merge is executed.

So, this will check the contents of
ActiveDocument.MailMerge.DataSource.FielNames against
ActiveDocument.MailMerge.Fields

And subsequently delete any merge fields fields in the master document that
aren't contained in the data source. I just have to make sure that I don't
mess up the contents of any conditional merge fields and invalidate them.
Luckily for me, the're not a player.

Ironically, the urgency for this has now passed and I won't have to deal
with it for the next four months, but thought you might find my solution of
interest. I've not tested it, but the theory seems sound to me.

Mmmm. In my experience, as soon as you open the document and the data source
doesn't "match", these errors would start displaying. As long as the main
merge document is not attached to a data source when you open it, and you
delete invalid fields before attaching the data source, this could work.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

  #5  
Old August 25th, 2004, 11:03 AM
Pete Bennett
external usenet poster
 
Posts: n/a
Default



"Cindy M -WordMVP-" wrote:

Mmmm. In my experience, as soon as you open the document and the data source
doesn't "match", these errors would start displaying. As long as the main
merge document is not attached to a data source when you open it, and you
delete invalid fields before attaching the data source, this could work.


Cindy,

You piqued my interest in this, so I decided to do a little experient and my
theory did seem to hold together..

In my example I have a merge master letter that contains a merge field
(email) that doesn't occur in my data source. Using VBA, when you open the
datasource, no checking is made to reconcile merge fields.. It's on the
'execute' that you get the errors pop up. Most probably things work
differently through Word's User Inteface, but we all know that, don't we? ;-)

Here's my test code..

Sub MergeTest()
Dim aDoc As Document
Dim aField As MailMergeField

Set aDoc = ActiveDocument

'Set the mail merge type
aDoc.MailMerge.MainDocumentType = wdFormLetters

' Connect data source (doesn't validate at this stage)
aDoc.MailMerge.OpenDataSource Name:="C:\Documents and Settings\User\My
Documents\Mailing List.csv"

' Remove surplus merge field from master document
For Each aField In aDoc.MailMerge.Fields
If aField.Type = wdFieldMergeField Then
If InStr(1, aField.Code.Text, "mergefield email", vbTextCompare) 0
Then
aField.Delete
End If
End If
Next aField

' Do the execute, which won't moan because the extra field has gone!
aDoc.MailMerge.Execute

' Close the master because it's no longer needed
aDoc.Close SaveChanges:=False

End Sub

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
unlinking merge fields Help Me General Discussion 1 August 6th, 2004 03:22 AM
Lost text fields in merge CGiannini General Discussion 5 June 4th, 2004 10:23 PM
Mail Merge two fields that have multiple lines with new line control code Eric Li Mailmerge 7 May 25th, 2004 06:10 PM
Merge fields in InsertText fields? Stephen Glynn New Users 1 May 24th, 2004 12:40 AM
Merge to Fax with SBS/Exchange? Tom Mailmerge 3 May 18th, 2004 11:22 PM


All times are GMT +1. The time now is 09:21 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.