G
Guest
I probably should know the answer to this, but I'm lost:
Because you can't do a mail merge in Word using more than one data source,
I've come up with this workaround... I'm going to take 2 separate documents,
merge them separately, and create a new master document with the newly-merged
documents attached as subdocuments. Then the user can open the master
document and print it as if it was one document all along.
I've got code established to open the 2 separate word documents and merge
them.
Private Sub Command199_Click()
On Error GoTo Err_Command199_Click
Dim oApp As Object
Dim objWord As Word.Document
Dim objword2 As Word.Document
Dim objword3 As Word.Document
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set objWord = GetObject("z:\shared folder\access database\LOI Template
Section 1.dot", "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource "z:\shared folder\access database\psc
data.mdb", , , , True, , , , , , , "TABLE tmpTblLOI", "SELECT * FROM
[TMPTBLLOI]"
objWord.MailMerge.Execute
objWord.SaveAs "z:\shared folder\access database\LOI Final Section 1.doc"
objWord.Close , False
Set objword2 = GetObject("z:\shared folder\access database\LOI Template
Section 2.dot", "Word.Document")
objword2.Application.Visible = True
objword2.MailMerge.OpenDataSource "z:\shared folder\access database\psc
data.mdb", , , , True, , , , , , , "TABLE tmpTblLOI_Checklist", "SELECT *
FROM [tmpTblLOI_Checklist]"
objword2.MailMerge.Execute
'objword2.SaveAs "z:\shared folder\access database\LOI Final Section 2.doc"
objword2.Close , False
Set objword3 = GetObject("z:\shared folder\access database\LOI Template
Master.dot", "Word.Document")
objword3.Application.Visible = True
Exit_Command199_Click:
Exit Sub
Err_Command199_Click:
MsgBox Err.Description
Resume Exit_Command199_Click
End Sub
The problem is this: after they are merged, the merged document is
established with a default name (for example 'formletter1') and I don't know
how to work with it. I'd like to save the document with a specific name so
that in my master document, I can reference the file specifically. My code
is this:
How do I do this, or does anyone have a better idea?
Because you can't do a mail merge in Word using more than one data source,
I've come up with this workaround... I'm going to take 2 separate documents,
merge them separately, and create a new master document with the newly-merged
documents attached as subdocuments. Then the user can open the master
document and print it as if it was one document all along.
I've got code established to open the 2 separate word documents and merge
them.
Private Sub Command199_Click()
On Error GoTo Err_Command199_Click
Dim oApp As Object
Dim objWord As Word.Document
Dim objword2 As Word.Document
Dim objword3 As Word.Document
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set objWord = GetObject("z:\shared folder\access database\LOI Template
Section 1.dot", "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource "z:\shared folder\access database\psc
data.mdb", , , , True, , , , , , , "TABLE tmpTblLOI", "SELECT * FROM
[TMPTBLLOI]"
objWord.MailMerge.Execute
objWord.SaveAs "z:\shared folder\access database\LOI Final Section 1.doc"
objWord.Close , False
Set objword2 = GetObject("z:\shared folder\access database\LOI Template
Section 2.dot", "Word.Document")
objword2.Application.Visible = True
objword2.MailMerge.OpenDataSource "z:\shared folder\access database\psc
data.mdb", , , , True, , , , , , , "TABLE tmpTblLOI_Checklist", "SELECT *
FROM [tmpTblLOI_Checklist]"
objword2.MailMerge.Execute
'objword2.SaveAs "z:\shared folder\access database\LOI Final Section 2.doc"
objword2.Close , False
Set objword3 = GetObject("z:\shared folder\access database\LOI Template
Master.dot", "Word.Document")
objword3.Application.Visible = True
Exit_Command199_Click:
Exit Sub
Err_Command199_Click:
MsgBox Err.Description
Resume Exit_Command199_Click
End Sub
The problem is this: after they are merged, the merged document is
established with a default name (for example 'formletter1') and I don't know
how to work with it. I'd like to save the document with a specific name so
that in my master document, I can reference the file specifically. My code
is this:
How do I do this, or does anyone have a better idea?