RichardOneil
MIS
Hi-
I have a database that creates a text file that serves as the datasource for a merge letter. I have created a form in Access with a command button that when clicked opens Word and the merge document and also performs the merge. However only the first record merges, nothing happens with the remaining records. Any thoughts, thanks in advance for any help? Here is the code:
Private Sub Command7_Click()
Dim WordApp As Object
Dim MailMerge As Object
'Open Word
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.Documents.Open FileName:="C:\totcomp\TotalCompLetter-mm.doc", ReadOnly:=False
Set MailMerge = WordApp.ActiveDocument.MailMerge
MailMerge.MainDocumentType = wdFormLetters
MailMerge.OpenDataSource Name:="C:\TotComp\source-empdata.txt", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, Revert:=False, Connection:=""
With MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With
End Sub
I have a database that creates a text file that serves as the datasource for a merge letter. I have created a form in Access with a command button that when clicked opens Word and the merge document and also performs the merge. However only the first record merges, nothing happens with the remaining records. Any thoughts, thanks in advance for any help? Here is the code:
Private Sub Command7_Click()
Dim WordApp As Object
Dim MailMerge As Object
'Open Word
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.Documents.Open FileName:="C:\totcomp\TotalCompLetter-mm.doc", ReadOnly:=False
Set MailMerge = WordApp.ActiveDocument.MailMerge
MailMerge.MainDocumentType = wdFormLetters
MailMerge.OpenDataSource Name:="C:\TotComp\source-empdata.txt", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, Revert:=False, Connection:=""
With MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With
End Sub