Combining two merged documents

C

CPutnam

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
 
D

Doug Robbins

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.

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

CPutnam

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.
 
D

Doug Robbins

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.

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

CPutnam

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.
 
D

Doug Robbins

If it ain't broke, don't fix it.

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

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