473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 26014
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.