P
Poppa Bear
using :
VS 2005 SE 2 ............ NOT VSTO
Word 2003
Office Interop v 10
Word Interop v 10
Trying to Mailmerge Word 2003 Document with Database.
1. With ACCESS.mdb works fine (lines (A) and (B) below active (C) and (D)
commented out
2. With SQL Server get message about failed to connect. (C) and (D) active
(A) and (B) commented out.
Using same Template file (CVSTemplate3.dot). Access and SQL server Xpress
DBs have same tables and data
Also get a dialog box about "Header Record Delimiters" telling me Data
fields and Data Records must be separated by delimiters. Haven't the faintest
idea what this refers to (sorry) . Can someone help please ? The connection
string for the SQL Server version is the same as I use in the main program
code to open the SQLServer Database - which works fine there, using Windows
Authentification. Have trawled the MS website and others for info with no
success. You are my last hope ! Help --- Please !!
Code snippets :
Private Sub btnOpenWord_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOpenWord.Click
Dim wrdApp As Word.Application =
CType(CreateObject("Word.Application"), Word.Application)
Dim wrdDoc As Word.Document =
CType(wrdApp.Documents.Add("CVSTemplate3.dot", False,
Word.WdDocumentType.wdTypeDocument, True), Word.Document)
Dim sqlQuery As String = "SELECT * FROM [tblEmployees] WHERE
EmployeeLastName LIKE '" & "Jones" & "';"
'' For ACCESS version
'Dim sDBPath As String = "C:\WORK\DBTestEmp.mdb"
'*********************** (A)
'Dim strConnect = System.Type.Missing
'*********************** (B)
'' FOR SQL SERVER Express version
Dim sDBPath As String = "C:\WORK\dbSQLEmpTest.mdf" '
**********************(C)
Dim strConnect As String = "Data
Source=c7e6i3;Database=dbSQLEmpTest;Integrated Security=True;" '
*********************(D)
Try
With wrdDoc.MailMerge
.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters
.OpenDataSource(Name:=sDBPath, Connection:=strConnect,
SQLStatement:=sqlQuery)
.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
.Execute(Pause:=False)
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
wrdApp.Visible = True
End Sub
VS 2005 SE 2 ............ NOT VSTO
Word 2003
Office Interop v 10
Word Interop v 10
Trying to Mailmerge Word 2003 Document with Database.
1. With ACCESS.mdb works fine (lines (A) and (B) below active (C) and (D)
commented out
2. With SQL Server get message about failed to connect. (C) and (D) active
(A) and (B) commented out.
Using same Template file (CVSTemplate3.dot). Access and SQL server Xpress
DBs have same tables and data
Also get a dialog box about "Header Record Delimiters" telling me Data
fields and Data Records must be separated by delimiters. Haven't the faintest
idea what this refers to (sorry) . Can someone help please ? The connection
string for the SQL Server version is the same as I use in the main program
code to open the SQLServer Database - which works fine there, using Windows
Authentification. Have trawled the MS website and others for info with no
success. You are my last hope ! Help --- Please !!
Code snippets :
Private Sub btnOpenWord_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOpenWord.Click
Dim wrdApp As Word.Application =
CType(CreateObject("Word.Application"), Word.Application)
Dim wrdDoc As Word.Document =
CType(wrdApp.Documents.Add("CVSTemplate3.dot", False,
Word.WdDocumentType.wdTypeDocument, True), Word.Document)
Dim sqlQuery As String = "SELECT * FROM [tblEmployees] WHERE
EmployeeLastName LIKE '" & "Jones" & "';"
'' For ACCESS version
'Dim sDBPath As String = "C:\WORK\DBTestEmp.mdb"
'*********************** (A)
'Dim strConnect = System.Type.Missing
'*********************** (B)
'' FOR SQL SERVER Express version
Dim sDBPath As String = "C:\WORK\dbSQLEmpTest.mdf" '
**********************(C)
Dim strConnect As String = "Data
Source=c7e6i3;Database=dbSQLEmpTest;Integrated Security=True;" '
*********************(D)
Try
With wrdDoc.MailMerge
.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters
.OpenDataSource(Name:=sDBPath, Connection:=strConnect,
SQLStatement:=sqlQuery)
.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
.Execute(Pause:=False)
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
wrdApp.Visible = True
End Sub