Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / September 2004

Tip: Looking for answers? Try searching our database.

Combining two merged documents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CPutnam - 10 Sep 2004 19:26 GMT
Hi, all.  I have two merges (Word 97) that both use Access queries as their
datasources (Access97).  The datasource queries have different fields in
them (because one of the queries combines multiple pieces of data from the
same table into one record).

Both merges work fine and I've even set up a macro to automatically do the
merge (because this will all be distributed to a number of different users
who will need to do this multiple times).  Here's the problem:

The macro does the first merge and saves the result into a new document (the
user is prompted for the document name; I'll call it DocA).  Then it
activates the second document, does the merge and saves that merge result to
a new document (call this one DocB).  Then it copies all the data from DocB
into DocA.  Then it closes DocB and activates DocA so that the user can do
any editing he/she needs to do.

BUT when DocB is closed, I get the "Invalid Merge Field" message for every
field in DocB.  If I click Cancel, I get the error message.  If I click OK,
then I get the field that was suggested.  Neither of these results is good.

I thought that clearing the data source from DocB would take care of the
problem, i.e. because the text that was being copied wouldn't look at all
like a merged document.  But then I found out that the error message
appeared when I CLOSED DocB.  So I thought that if I closed without saving,
that might take care of the problem.  But it didn't.

Here's the macro that I'm using.  Any ideas will be greatly appreciated!!
Thanks.  Carol.

P.S.  There will also be users using this macro in Word 2002 so if anyone
can see any problems that I'll be creating for myself, please let me know.
Thanks again.
----------------------------------------------------------------------------
-
Sub ProjectAbstractMerge()
'
' ProjectAbstractMerge Macro
' Macro recorded 09/09/04 by cpapishputnam
'

On Error GoTo Err_NothingtoMerge

   ChangeFileOpenDirectory "C:\Download\ProjAbstractMergeFiles\"
   Rem Documents.Open FileName:="ProjectAbstractTEMPLATE97.doc", _
   rem     ConfirmConversions:=True, ReadOnly:=False,
AddToRecentFiles:=False, _
   rem     PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
   rem     WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
   rem     wdOpenFormatAuto
   ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle

        'If the document has not yet been saved
       'Ask the user to provide a filename
   strDocName = InputBox("Please enter a new name " & _
         "for your merged document.")

   ActiveDocument.SaveAs FileName:="c:\download\ProjAbstractMergeFiles\" &
strDocName

    Selection.Find.ClearFormatting
   With Selection.Find
       .Text = "Ecoregion:"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = False

   End With
   Selection.Find.Execute
   Selection.MoveUp Unit:=wdLine, Count:=2

   Documents.Open FileName:="ProjectAbstract_keyContacts.doc", _
       ConfirmConversions:=True, ReadOnly:=False, AddToRecentFiles:=False,
_
       PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
       WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
       wdOpenFormatAuto
   ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
   ActiveDocument.SaveAs
FileName:="c:\download\ProjAbstractMergeFiles\ProjectAbstract_KeyContactsMer
ged.doc"

Documents("C:\download\ProjAbstractMergeFiles\ProjectAbstract_KeyContactsMer
ged.doc").Activate
   Set doc = ActiveDocument
   doc.MailMerge.MainDocumentType = wdNotAMergeDocument

   Selection.WholeStory
   Selection.Copy

   Documents("c:\download\ProjAbstractMergeFiles\" & strDocName &
".doc").Activate
   Selection.Paste

   ActiveDocument.Save

   Documents("ProjectAbstract_keyContactsmerged.doc").Close
SaveChanges:=wdDoNotSaveChanges

   Documents("c:\download\ProjAbstractMergeFiles\" & strDocName &
".doc").Activate

ProcessDone:
   End

Err_NothingtoMerge:
   Select Case Err.Number
   Case 5631
       Resume Next
   Case Else
       MsgBox "Error # " & Err.Number & ": " & Err.Description, vbOKOnly +
vbCritical, strProcessName
   End Select
   GoTo ProcessDone

End Sub
Doug Robbins - 11 Sep 2004 04:09 GMT
The problem is that you are not executing either of the mailmerges.  All you
are doing is copying a document conatining mergefields and pasting it into
another mailmerge main document the data source of which does not contain
the mergefields that are included in what was pasted.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hi, all.  I have two merges (Word 97) that both use Access queries as
> their
[quoted text clipped - 125 lines]
>
> End Sub
CPutnam - 11 Sep 2004 12:58 GMT
Ahah!  You're saying that instead of this line:
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle" I need this:

With ActiveDocument.MailMerge
       .Destination = wdSendToNewDocument
       .SuppressBlankLines = True
       With .DataSource
           .FirstRecord = wdDefaultFirstRecord
           .LastRecord = wdDefaultLastRecord
       End With
       .Execute Pause:=False
   End With

Since I saw the actual data, I didn't think there was a difference.  Many
thanks.   Carol.

> The problem is that you are not executing either of the mailmerges.  All you
> are doing is copying a document conatining mergefields and pasting it into
[quoted text clipped - 94 lines]
> >    ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
> >    ActiveDocument.SaveAs

FileName:="c:\download\ProjAbstractMergeFiles\ProjectAbstract_KeyContactsMer
> > ged.doc"

Documents("C:\download\ProjAbstractMergeFiles\ProjectAbstract_KeyContactsMer
> > ged.doc").Activate
> >    Set doc = ActiveDocument
[quoted text clipped - 29 lines]
> >
> > End Sub
Doug Robbins - 11 Sep 2004 13:06 GMT
Yes, that was it.  Then of course, if your datasource contains multiple
records, you are going to end up with a new document consisting of a Section
for each of those records which you will then need to pull apart.  I did not
feel like getting into that last night.  This morning however, I am
wondering if you can just toggle the fields as you were doing, then Unlink
the fields which would result in the document containing (as distinct from
displaying) the data from a single record.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Ahah!  You're saying that instead of this line:
> ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle" I need this:
[quoted text clipped - 174 lines]
>> >
>> > End Sub
CPutnam - 12 Sep 2004 14:30 GMT
Well, it's working fine just doing the actual merge and saving the document
that results.  I'd have to think more about your new suggestion and I just
don't have the luxury of time to do that!

Thanks for your help.  Carol.

> Yes, that was it.  Then of course, if your datasource contains multiple
> records, you are going to end up with a new document consisting of a Section
[quoted text clipped - 142 lines]
> >> >    ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
> >> >    ActiveDocument.SaveAs

FileName:="c:\download\ProjAbstractMergeFiles\ProjectAbstract_KeyContactsMer
> >> > ged.doc"

Documents("C:\download\ProjAbstractMergeFiles\ProjectAbstract_KeyContactsMer
> >> > ged.doc").Activate
> >> >    Set doc = ActiveDocument
[quoted text clipped - 31 lines]
> >> >
> >> > End Sub
Doug Robbins - 12 Sep 2004 18:22 GMT
If it ain't broke, don't fix it.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Well, it's working fine just doing the actual merge and saving the
> document
[quoted text clipped - 217 lines]
>> >> >
>> >> > End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.