A
ajagadambe
Hi all!
I am using VB.Net Pro to open a mail merge word document and use an MS
Access 2003 table.
The thing is the mail merge is working, but I want to automate the
process of selecting the table.
Right now, it opens the correct word document, and looks at the correct
database, but the thing is the use is PROMPTED to select the table. I
want to know how i can automate this. I have been looking for a
solution for the past week and still not successful! - the table i want
to select is the customer table.
The code i am using is the following:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim wrdApp As New Word.Application
Dim wrdDoc As Word.Document
Dim wrdMerger As Word.MailMerge
Dim strTemplateName As String
Dim strDataSourceDB As String
Dim strDataSourceTable As String
Dim testCmd As New OleDbCommand("SELECT * FROM Customer")
strDataSourceDB = Application.StartupPath.ToString &
"\East-West Travel Agents.mdb"
strTemplateName = Application.StartupPath.ToString &
"\testMergeLetter.doc"
strDataSourceTable = "Customer"
wrdDoc = wrdApp.Documents.Add(strTemplateName)
wrdMerger = wrdDoc.MailMerge
With wrdMerger
.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters
.OpenDataSource(Name:=strDataSourceDB, _
linktosource:=True, addtorecentfiles:=False, _
connection:="TABLE " & "'" & strDataSourceTable &
"'")
.Destination = Word.WdMailMergeDestination.wdSendToPrinter
.Execute()
wrdDoc.Close(False)
wrdApp.Quit()
End With
End Sub
Thank you in advance for any help!!! )
I am using VB.Net Pro to open a mail merge word document and use an MS
Access 2003 table.
The thing is the mail merge is working, but I want to automate the
process of selecting the table.
Right now, it opens the correct word document, and looks at the correct
database, but the thing is the use is PROMPTED to select the table. I
want to know how i can automate this. I have been looking for a
solution for the past week and still not successful! - the table i want
to select is the customer table.
The code i am using is the following:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim wrdApp As New Word.Application
Dim wrdDoc As Word.Document
Dim wrdMerger As Word.MailMerge
Dim strTemplateName As String
Dim strDataSourceDB As String
Dim strDataSourceTable As String
Dim testCmd As New OleDbCommand("SELECT * FROM Customer")
strDataSourceDB = Application.StartupPath.ToString &
"\East-West Travel Agents.mdb"
strTemplateName = Application.StartupPath.ToString &
"\testMergeLetter.doc"
strDataSourceTable = "Customer"
wrdDoc = wrdApp.Documents.Add(strTemplateName)
wrdMerger = wrdDoc.MailMerge
With wrdMerger
.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters
.OpenDataSource(Name:=strDataSourceDB, _
linktosource:=True, addtorecentfiles:=False, _
connection:="TABLE " & "'" & strDataSourceTable &
"'")
.Destination = Word.WdMailMergeDestination.wdSendToPrinter
.Execute()
wrdDoc.Close(False)
wrdApp.Quit()
End With
End Sub
Thank you in advance for any help!!! )