473,503 Members | 12,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Word Mailmerge

Hi

I am trying to do a word mailmerge form within my vb.net app. My problem is
how to do a query on one of my tables and use the result as the mail merge
datasource. Any help would be appreciated.

Thanks

Regards
Nov 20 '05 #1
10 26060
Can word make use of an XML file, if so you could output that. Failing that
ourput to an Acess or Excel speadsheet.

OHM

John wrote:
Hi

I am trying to do a word mailmerge form within my vb.net app. My
problem is how to do a query on one of my tables and use the result
as the mail merge datasource. Any help would be appreciated.

Thanks

Regards

Nov 20 '05 #2
Hi John,
I am trying to do a word mailmerge form within my vb.net app. My problem is
how to do a query on one of my tables and use the result as the mail merge
datasource. Any help would be appreciated.

What's the data source? And does it support saving the query as a query/view?

If not, does it have an ODBC interface (driver)?

And how many characters would you estimate the query could contain, max?

Finally, which version(s) of word would you be dealing with?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

Nov 20 '05 #3
here is a sample I wrote for a friend that needed the same thing.
Notice the need of a DSN. This is using odbc. I couldn't find any other
way.
also, notice the hardcoded path to the template file. You will need to
adjust for yours instead.
My template file had just 1 mail merge field named 'au_fname'.

Private Sub DoMailMerge()
Dim w As New Word.Application
Dim d As Word.Document
d = w.Documents.Open("c:\some.dot")

Dim strConnection As String

strConnection = "DSN=bob;uid=sa;pwd=;"
d.MailMerge.OpenDataSource("c:\t.txt", , , , , , , , , , ,
strConnection, "SELECT * FROM authors")

d.MailMerge.Execute()
d.Close(False)
w.Visible = True
End Sub

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Oc**************@tk2msftngp13.phx.gbl...
Hi

I am trying to do a word mailmerge form within my vb.net app. My problem is how to do a query on one of my tables and use the result as the mail merge
datasource. Any help would be appreciated.

Thanks

Regards

Nov 20 '05 #4
Hi

The database backend is access. Query length would be less then 200
characters. Word version 2000.

Thanks

Regards
"Cindy Meister -WordMVP-" <Ci**********@XSPMswissonline.com> wrote in
message news:VA.000087c5.01a0de62@speedy...
Hi John,
I am trying to do a word mailmerge form within my vb.net app. My problem is how to do a query on one of my tables and use the result as the mail merge datasource. Any help would be appreciated.
What's the data source? And does it support saving the query as a

query/view?
If not, does it have an ODBC interface (driver)?

And how many characters would you estimate the query could contain, max?

Finally, which version(s) of word would you be dealing with?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

Nov 20 '05 #5
My database is access. I just can't figure out how to run a query on an
access table and use the result as the datasource.

Thanks

Regards
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bl**********@titan.btinternet.com...
Can word make use of an XML file, if so you could output that. Failing that ourput to an Acess or Excel speadsheet.

OHM

John wrote:
Hi

I am trying to do a word mailmerge form within my vb.net app. My
problem is how to do a query on one of my tables and use the result
as the mail merge datasource. Any help would be appreciated.

Thanks

Regards


Nov 20 '05 #6
Hi John,
The database backend is access. Query length would be less then 200
characters. Word version 2000.

<<I am trying to do a word mailmerge form within my vb.net app. My
problem is how to do a query on one of my tables and use the result
as the mail merge datasource.>>

Well, looked at from a purely Access POV, you'd use DAO to generate a
query in Access, then link the mail merge to that. Since the general
opinion in these groups is that you shouldn't use DAO, there are
alternatives.

As long as the SQL-statement you use to build your query is 510
characters or less (we're dealing with a limit in Word, here), you
can set the query while linking in the data source, using the
SQLStatement and SQLStatement1 arguments of the OpenDataSource method
for the MailMerge.DataSource object.

For 255 characters or less, you also have the option of setting the
.QueryString property at any time.

The third possibility would be to create a *.dqy for the query using
MS Query and call that as the data source.

From the sound of it, you should be able to do everything you need
using the .OpenDataSource method's argument(s). Since Word is very
picky about the punctuation used in SQL, your best bet is to open up
Word and record a macro while linking to the data source, going over
MS Query. If you activate the "Select method" checkbox in the Open
Data source dialog box, you should get the option to choose ODBC, and
then Word should offer MS Query (if it's installed).

Why MS Query (and ODBC)? Word mail merge provides two possible
connection methods for Access databases: DDE and ODBC. DDE requires
actually opening the Access interface, which can lead to all sorts of
problems. ODBC will give you backwards and forwards compatibility
with all current versions of Office (97 through 2003). As long as
you're dealing with "typical" Office installations, you don't need to
worry about DSNs, since the basic mail merge DSNs are installed by
default.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)

Nov 20 '05 #7
Hi

What is t.txt file in this example?

Thanks

Regards

"Kirk" <mc*******@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
here is a sample I wrote for a friend that needed the same thing.
Notice the need of a DSN. This is using odbc. I couldn't find any other
way.
also, notice the hardcoded path to the template file. You will need to
adjust for yours instead.
My template file had just 1 mail merge field named 'au_fname'.

Private Sub DoMailMerge()
Dim w As New Word.Application
Dim d As Word.Document
d = w.Documents.Open("c:\some.dot")

Dim strConnection As String

strConnection = "DSN=bob;uid=sa;pwd=;"
d.MailMerge.OpenDataSource("c:\t.txt", , , , , , , , , , ,
strConnection, "SELECT * FROM authors")

d.MailMerge.Execute()
d.Close(False)
w.Visible = True
End Sub

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Oc**************@tk2msftngp13.phx.gbl...
Hi

I am trying to do a word mailmerge form within my vb.net app. My problem

is
how to do a query on one of my tables and use the result as the mail merge datasource. Any help would be appreciated.

Thanks

Regards


Nov 20 '05 #8
Hi

I have tried;

wrdMailMerge.OpenDataSource(Name:="F:\dbpath\mydb. mdb",
Connection:=m_objConnection, SQLStatement:="SELECT * FROM Contacts")

but I get a 'Type Mismatch' error. What am I doing wrong?

Thanks

Regards

"Kirk" <mc*******@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
here is a sample I wrote for a friend that needed the same thing.
Notice the need of a DSN. This is using odbc. I couldn't find any other
way.
also, notice the hardcoded path to the template file. You will need to
adjust for yours instead.
My template file had just 1 mail merge field named 'au_fname'.

Private Sub DoMailMerge()
Dim w As New Word.Application
Dim d As Word.Document
d = w.Documents.Open("c:\some.dot")

Dim strConnection As String

strConnection = "DSN=bob;uid=sa;pwd=;"
d.MailMerge.OpenDataSource("c:\t.txt", , , , , , , , , , ,
strConnection, "SELECT * FROM authors")

d.MailMerge.Execute()
d.Close(False)
w.Visible = True
End Sub

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Oc**************@tk2msftngp13.phx.gbl...
Hi

I am trying to do a word mailmerge form within my vb.net app. My problem

is
how to do a query on one of my tables and use the result as the mail merge datasource. Any help would be appreciated.

Thanks

Regards


Nov 20 '05 #9
Believe it or not, it is just a dummy file. It must exist, and the file
path must be passed to the argument, but the file can be empty.

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi

What is t.txt file in this example?

Thanks

Regards

"Kirk" <mc*******@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
here is a sample I wrote for a friend that needed the same thing.
Notice the need of a DSN. This is using odbc. I couldn't find any other
way.
also, notice the hardcoded path to the template file. You will need to
adjust for yours instead.
My template file had just 1 mail merge field named 'au_fname'.

Private Sub DoMailMerge()
Dim w As New Word.Application
Dim d As Word.Document
d = w.Documents.Open("c:\some.dot")

Dim strConnection As String

strConnection = "DSN=bob;uid=sa;pwd=;"
d.MailMerge.OpenDataSource("c:\t.txt", , , , , , , , , , ,
strConnection, "SELECT * FROM authors")

d.MailMerge.Execute()
d.Close(False)
w.Visible = True
End Sub

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Oc**************@tk2msftngp13.phx.gbl...
Hi

I am trying to do a word mailmerge form within my vb.net app. My
problem is
how to do a query on one of my tables and use the result as the mail

merge datasource. Any help would be appreciated.

Thanks

Regards



Nov 20 '05 #10
John,

The demo was originally used against an SQL Server database (or really, any
ODBC database). If you connecting to an Access db, it changes slightly.
Use this line instead.

wrdMailMerge.OpenDataSource(Name:="F:\dbpath\mydb. mdb",
SQLStatement:="SELECT * FROM Contacts")

The connection argument should not be necessary.

Hope that helps

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:eU**************@TK2MSFTNGP11.phx.gbl...
Hi

I have tried;

wrdMailMerge.OpenDataSource(Name:="F:\dbpath\mydb. mdb",
Connection:=m_objConnection, SQLStatement:="SELECT * FROM Contacts")

but I get a 'Type Mismatch' error. What am I doing wrong?

Thanks

Regards

"Kirk" <mc*******@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
here is a sample I wrote for a friend that needed the same thing.
Notice the need of a DSN. This is using odbc. I couldn't find any other
way.
also, notice the hardcoded path to the template file. You will need to
adjust for yours instead.
My template file had just 1 mail merge field named 'au_fname'.

Private Sub DoMailMerge()
Dim w As New Word.Application
Dim d As Word.Document
d = w.Documents.Open("c:\some.dot")

Dim strConnection As String

strConnection = "DSN=bob;uid=sa;pwd=;"
d.MailMerge.OpenDataSource("c:\t.txt", , , , , , , , , , ,
strConnection, "SELECT * FROM authors")

d.MailMerge.Execute()
d.Close(False)
w.Visible = True
End Sub

Kirk Graves

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Oc**************@tk2msftngp13.phx.gbl...
Hi

I am trying to do a word mailmerge form within my vb.net app. My
problem is
how to do a query on one of my tables and use the result as the mail

merge datasource. Any help would be appreciated.

Thanks

Regards



Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1257
by: SmartHead | last post by:
Hi, I would like to open aword document and insert mailmerge fields dinamically using c#.net. While working around it, I created a MailMerge object and used its "Field" property. But its...
2
13481
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
3
1067
by: Brian Henry | last post by:
Is there any quick way to create a mail merge listing from VB.NET in word. I have a dataset full of addresses and names that I need to create labels for and would like to send that data to word so...
2
3354
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
0
916
by: Steve | last post by:
Can anyone point me to a source that lays out the full word mailmerge automation approach including events, properties, etc. and how they can be used in a vb.net application. I've looked around on...
0
1049
by: pdsasse | last post by:
I am trying to create a mailmerge document in MS Word that uses a DAO recordset as it's data source. So far, I have not had any success. Can anyone stear me in the correct direction?
2
1597
by: code937 | last post by:
Hi Guys, ive got to deliver some software in ONE hour and im not as finished as i thought id be!!!.... Basically is Mail Merge. I have a word template with <<firstname>><lastname>> and the rest...
0
1285
by: mleerog | last post by:
Hope someone can shed some light on a tricky error. I am trying to automate a mailmerge in VB.NET using Word 2003. The main document is a previously existing Word file. The data source is a text...
0
2530
by: dbsog7777 | last post by:
I was trying to use the sample code below, but I encountered two errors: Application.DoEvents() and AutoText(entry). I am not sure how to correct the errors. I trying to use the sample code to...
0
7193
marktang
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,...
0
7316
jinu1996
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...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.