View Single Post
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Automating Mail merge between Word 2003 and Access 2003 using VB.NET

I believe that

.OpenDataSource(Name:=strDataSourceDB, _
linktosource:=True, addtorecentfiles:=False, _
connection:="TABLE " & "'" & strDataSourceTable &
"'")

Should be:

.OpenDataSource Name:=strDataSourceDB, _
linktosource:=True, addtorecentfiles:=False, _
connection:="TABLE " & & strDataSourceTable


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
ups.com...
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!!! )