Good afternoon. My name is Don, and I'm working with my first dealings with Mail Merge.
I have been reading a discussion started by a user called Chubbly Geezer, and have been trying different solutions presented to him.
I am using VB from Visual Studio 2005, and SQL Server 2005 Express as a backend, with Office 2003.
My SQL Server is set up with Mixed security.
I am trying to use the doc.MailMerge.O penDataSource in my code to cause the work document to query the database when I open the document.
The code I am using is as Follows:
My objects are declared at the class level:
Protected appWord As Object
Protected doc As Microsoft.Offic e.Interop.Word. Document
Protected bFormClosed As Boolean = True
Protected SqlConnectionSt ring = My.Settings.Mou ntainRailMarket ingConnectionSt ring
Protected connectionStrin g As String = SqlConnectionSt ring
Protected connection As New SqlConnection(c onnectionString )
Protected sql As String
Protected cmd As New SqlCommand(sql, connection)
Protected daMarketingClie nt As New SqlDataAdapter( cmd)
Protected dsMarketingClie nt As New DataSet
Protected pRow As DataRow
Private myNull = System.DBNull.V alue
and my code is as follows:
Private Sub btnMailingLabel s_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnMailingLabel s.Click
'---------------------------------------------------------------------------------------------------------------------------
' Source: btnMailingLabel s_Click
'
' Change Log Modification
'
' Date Author SCN Description
' ---- ------ -------- ------------------------------------------------------------------------------------
' 5/12/2007 djd Initial form
'---------------------------------------------------------------------------------------------------------------------------
Try
appWord.Visible = True
OpenFileDialog1 .Filter = "Text files (*.DOC)|*.DOC"
OpenFileDialog1 .ShowDialog() 'display Open dialog box
doc = appWord.Documen ts.Open(OpenFil eDialog1.FileNa me)
doc.MailMerge.O penDataSource(" C:\Documents and Settings\Don\My Documents\My Data Sources\Durbin Greenbrier Marketing List\localhost_ sqlexpress MountainRailMar keting ClientList.odc" , _
Connection:="Pr ovider=SQLOLEDB .1;Persist Security Info=False;User ID=DurbinMarket ingUser;Passwor d=letmein!@#;In itial Catalog=Mountai nRailMarketing; Data Source=localhos t\sqlexpress;", _
SQLStatement:=" select * from ""ClientLis t"" WHERE cltPrintFlag = 0", _
SubType:=Word.W dMergeSubType.w dMergeSubTypeOt her)
appWord.Documen ts(1).Activate( )
doc.Activate()
bFormClosed = False
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub
When I try to execute this, I get presented with a SQL Server Login window
with the login information in place, when I try to "test the connection" I get a message Test connection failed because of an error in the initializing providor. Login failed for DurbinMarketing User.
And I get a message that Windows was unable to open the datasource.
I would appreciate any help that you might be able to give.
Thank You
I have been reading a discussion started by a user called Chubbly Geezer, and have been trying different solutions presented to him.
I am using VB from Visual Studio 2005, and SQL Server 2005 Express as a backend, with Office 2003.
My SQL Server is set up with Mixed security.
I am trying to use the doc.MailMerge.O penDataSource in my code to cause the work document to query the database when I open the document.
The code I am using is as Follows:
My objects are declared at the class level:
Protected appWord As Object
Protected doc As Microsoft.Offic e.Interop.Word. Document
Protected bFormClosed As Boolean = True
Protected SqlConnectionSt ring = My.Settings.Mou ntainRailMarket ingConnectionSt ring
Protected connectionStrin g As String = SqlConnectionSt ring
Protected connection As New SqlConnection(c onnectionString )
Protected sql As String
Protected cmd As New SqlCommand(sql, connection)
Protected daMarketingClie nt As New SqlDataAdapter( cmd)
Protected dsMarketingClie nt As New DataSet
Protected pRow As DataRow
Private myNull = System.DBNull.V alue
and my code is as follows:
Private Sub btnMailingLabel s_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnMailingLabel s.Click
'---------------------------------------------------------------------------------------------------------------------------
' Source: btnMailingLabel s_Click
'
' Change Log Modification
'
' Date Author SCN Description
' ---- ------ -------- ------------------------------------------------------------------------------------
' 5/12/2007 djd Initial form
'---------------------------------------------------------------------------------------------------------------------------
Try
appWord.Visible = True
OpenFileDialog1 .Filter = "Text files (*.DOC)|*.DOC"
OpenFileDialog1 .ShowDialog() 'display Open dialog box
doc = appWord.Documen ts.Open(OpenFil eDialog1.FileNa me)
doc.MailMerge.O penDataSource(" C:\Documents and Settings\Don\My Documents\My Data Sources\Durbin Greenbrier Marketing List\localhost_ sqlexpress MountainRailMar keting ClientList.odc" , _
Connection:="Pr ovider=SQLOLEDB .1;Persist Security Info=False;User ID=DurbinMarket ingUser;Passwor d=letmein!@#;In itial Catalog=Mountai nRailMarketing; Data Source=localhos t\sqlexpress;", _
SQLStatement:=" select * from ""ClientLis t"" WHERE cltPrintFlag = 0", _
SubType:=Word.W dMergeSubType.w dMergeSubTypeOt her)
appWord.Documen ts(1).Activate( )
doc.Activate()
bFormClosed = False
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub
When I try to execute this, I get presented with a SQL Server Login window
with the login information in place, when I try to "test the connection" I get a message Test connection failed because of an error in the initializing providor. Login failed for DurbinMarketing User.
And I get a message that Windows was unable to open the datasource.
I would appreciate any help that you might be able to give.
Thank You
Comment