?
Solved

Setting up VB6 Mail Merge

Posted on 2011-02-17
6
Medium Priority
?
272 Views
Last Modified: 2012-05-11
I am adding ome functionailty to a vb6 system setup years ago. I need to add a mailmerge functionality. How do i setup a mailmerge document in word and VB6?
0
Comment
Question by:ict-torquilclark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Cluskitt
ID: 34917060
Depends on the office version. 2003 and previous, there's lots of tutorials on the net, and it's pretty straight-forward. After 2007 things changed a bit (like not being able to use parameter queries. Not directly anyway).
0
 
LVL 1

Author Comment

by:ict-torquilclark
ID: 34917084
I have Word 2007
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 34917200
I struggled quite a bit to get a mail merge working because of a parameter query (a query that takes a parameter from, for example, a text box). In the end, I ended up creating the query on the fly, so it wouldn't have any parameters on the merge stage.

See if this helps you:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26559967.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:ict-torquilclark
ID: 34917445
Ok. How do I actually add merge fields to word?
0
 
LVL 18

Accepted Solution

by:
Cluskitt earned 2000 total points
ID: 34917566
First, you need to set up the fields in a word file:

1- Insert-> Quick pieces (translation?) -> Field
2- mailmerge type, use the name of the field.
3- Repeat until all are done.

If you want to do it manually, just go to mailings and you can use the wizard, as long as your query is fully defined. If not, what you have to do is a bit of VBA. Like:

Dim WDApp, myDoc, svDoc, tmpDoc As Object
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
sFile = "C:\Mypath\Myfile.docx"
Set WDApp = CreateObject("Word.Application")
WDApp.Application.Visible = True
Set myDoc = WDApp.Documents.Open(sFile)
CurrentDb.QueryDefs("qryMerge").SQL="SELECT field1, field2 FROM table WHERE field1=" & txtbox1

WDApp.ActiveDocument.MailMerge.OpenDataSource Name:=CurrentDb.Name, ConfirmConversions:=True, ReadOnly:= False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:= "", Revert:=False, Format:=wdOpenFormatAuto, Connection:= "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=CurrentDb.Name;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global " , SQLStatement:="SELECT * FROM `qryMerge`", SQLStatement1:="", SubType:=wdMergeSubTypeAccess
With WDApp.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

Open in new window

0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 34917576
Ignore svDoc and tmpDoc declarations. My code uses 3 files and shifts data between them.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question