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.OpenDataSource 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.Office.Interop.Word.Document
Protected bFormClosed As Boolean = True
Protected SqlConnectionString = My.Settings.MountainRailMarketingConnectionString
Protected connectionString As String = SqlConnectionString
Protected connection As New SqlConnection(connectionString)
Protected sql As String
Protected cmd As New SqlCommand(sql, connection)
Protected daMarketingClient As New SqlDataAdapter(cmd)
Protected dsMarketingClient As New DataSet
Protected pRow As DataRow
Private myNull = System.DBNull.Value
and my code is as follows:
Private Sub btnMailingLabels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMailingLabels.Click
'---------------------------------------------------------------------------------------------------------------------------
' Source: btnMailingLabels_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.Documents.Open(OpenFileDialog1.FileName)
doc.MailMerge.OpenDataSource("C:\Documents and Settings\Don\My Documents\My Data Sources\Durbin Greenbrier Marketing List\localhost_sqlexpress MountainRailMarketing ClientList.odc", _
Connection:="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=DurbinMarketingUser;Password=letmein!@#;Initial Catalog=MountainRailMarketing;Data Source=localhost\sqlexpress;", _
SQLStatement:="select * from ""ClientList"" WHERE cltPrintFlag = 0", _
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)
appWord.Documents(1).Activate()
doc.Activate()
bFormClosed = False
Catch ex As Exception
MsgBox(ex.Message)
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 DurbinMarketingUser.
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
2 1737
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.OpenDataSource 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.Office.Interop.Word.Document
-
Protected bFormClosed As Boolean = True
-
Protected SqlConnectionString = My.Settings.MountainRailMarketingConnectionString
-
Protected connectionString As String = SqlConnectionString
-
Protected connection As New SqlConnection(connectionString)
-
Protected sql As String
-
Protected cmd As New SqlCommand(sql, connection)
-
Protected daMarketingClient As New SqlDataAdapter(cmd)
-
Protected dsMarketingClient As New DataSet
-
Protected pRow As DataRow
-
Private myNull = System.DBNull.Value
-
-
and my code is as follows:
-
-
Private Sub btnMailingLabels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMailingLabels.Click
-
'---------------------------------------------------------------------------------------------------------------------------
-
' Source: btnMailingLabels_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.Documents.Open(OpenFileDialog1.FileName)
-
doc.MailMerge.OpenDataSource("C:\Documents and Settings\Don\My Documents\My Data Sources\Durbin Greenbrier Marketing List\localhost_sqlexpress MountainRailMarketing ClientList.odc", _
-
Connection:="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=DurbinMarketingUser;Password=letmein!@#;Initial Catalog=MountainRailMarketing;Data Source=localhost\sqlexpress;", _
-
SQLStatement:="select * from ""ClientList"" WHERE cltPrintFlag = 0", _
-
SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)
-
appWord.Documents(1).Activate()
-
doc.Activate()
-
bFormClosed = False
-
Catch ex As Exception
-
MsgBox(ex.Message)
-
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 DurbinMarketingUser.
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
Hello diston52!
Looks like you're almost there, assuming you have the same problem I had a couple months ago. You should configure the connection string to reflect the datasource being used. The code may be looking for a source and cannot find it.
Again, provided you're having a similar issue:
(1) Hit that wonderful button near the provider info textbox
(2) Test your connection again
Also, what extension is .odc?
Good luck!
Dököll
Hi Don,
I am looking for working on Mail Merge from my VB.Net aplication. I use MS Access as my DB. I have saved templates in rtf format, have dataset to whom I have to send letters. But, I can't figure out how to perform thhe further steps to complete Mail Merge. It would be nice of you, if you can give me some idea on how to move ahead or proceed to perform Mail Merge from my application. I believe you can help to some extend as you have already worked on it. I am looking for any guidance from days, but couldn't get started yet.
I would appreciate, if your solution can be a good start up for my problem. Please help me or guide me atleast.
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: antonovaCCCS |
last post by:
In our old VB 6 application we utilize a mail merge feature of Word 97 with
MS Access. A table in Access is populated from VB and a Word template is
wired to that table. So all we do in the code is...
|
by: Aaron |
last post by:
hello,
i am perfoming a mail merge with the following code.
Public Function MergeIt()
Dim objWord As Object
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word visible....
|
by: Lisa |
last post by:
I have a query named QryDept where one of the fields is DeptID. The query is
used for the data source of a mail merge letter. I would like to control
which department is to get the mail merge...
|
by: Squirrel |
last post by:
Hi everyone,
I've created a mail merge Word doc. (using Office XP) , the data source is
an Access query.
Functionality I'm attempting to set up is:
User sets a boolean field to true for...
|
by: Andy Davis |
last post by:
I have set up a mail merge document in Word 2003 which gets its data from my
Access 2000 database. I want to set up a button on a form that:
1. runs the query to provide the dat for the merge...
|
by: lesperancer |
last post by:
I have 3 tables (office97)
tblQuote
quoteNbr
tblDetails ( quote : 1 <-> M: quoteDetails)
quoteNbr
detailLine
product
value
|
by: crealesmith |
last post by:
Firstly, I have no problem with mail merging to Word, VB code for that
works perfectly.
On one mail merge I need to merge 15 fields of data that are from 3
seperate records.
The 3 records are all...
|
by: =?Utf-8?B?QmFkaXM=?= |
last post by:
Hi,
I'm trying to follow a mail merging example in C#.Net that I got from:
http://support.microsoft.com/default.aspx/kb/301659
and in one the methods:
Word.Application wrdApp;
Word._Document...
|
by: =?Utf-8?B?VHJ1cHRpIERhbGlh?= |
last post by:
Hi to all,
I am new in this newsgroup and new to .NET also. I am creating an
application where I have to perform Mail Merge from my program. I have
created a form which contain RTB and user can...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |