473,414 Members | 1,675 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,414 software developers and data experts.

Help With Merge to A Word Document

Hi, I am using the following code in Access 2003 to merge data from a query to a table in a Word document:

Private Sub BtnMerge_Click()
Dim db As DAO.Database
Dim objWord As Word.Application
Dim strDocumentPath As String

Set db = CurrentDb()
Set objWord = GetObject(, "Word.Application")

If Err.Number <> 0 Then
Set objWord = CreateObject("Word.Application")
End If

objWord.Visible = True
strMyTemplatePath = "C:\Users\Bill\Documents\Databases\Documents\ACP11 7Section2.dot"

objWord.Documents.Add Template:=strDocumentPathPath, NewTemplate:=False

objWord.ActiveDocument.MailMerge.OpenDataSource _
Name:=db.Name, _
LinkToSource:=True, _
Connection:="QUERY QryACP117Sect2", _
SQLStatement:="Select * from [QryACP117Sect2]"

objWord.ActiveDocument.MailMerge.Execute
End Sub

The code works fine and merges to produce a Word document. The problem is that the completed document is produced with only one record (Table Row) per page, which I guess is 'letter' or 'label' merge format, rather than the 'directory' format I was hoping for i.e. with records following one another and spilling over pages.

If I open the document in Word and do a normal mail merge it produces the directory style document I want.

Any advice or solutions would be gratefully received.
Jan 14 '08 #1
3 2139
FishVal
2,653 Expert 2GB
Hi, HarryTheB.

If you are able to do it manually, then just record a macro and see the generated VBA code.

Regards,
Fish

P.S. I guess in your case you should set MailMerge.MainDocumentType property.
Jan 14 '08 #2
Hi, Fish
I can't thank you enough. I simply added the line:

objWord.ActiveDocument.MailMerge.MainDocumentType = wdDirectory

and it works a treat. Once again many thanks

HarryTheB
Jan 14 '08 #3
FishVal
2,653 Expert 2GB
Not a problem.
Good luck.
Jan 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve M | last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want...
5
by: Tom Keane | last post by:
Okay, so the deal is, I am doing a mail merge document in order to print invoices. The field I get the amount of money is "invAmount". What I would like to do is be able to manipulate this number...
8
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...
0
by: Lauren Wilson | last post by:
Hi folks, I am using the following code to merge data from an Access table to a pre-defined Word 2000 merge document. It al works fine except for ONE problem -- after the merged document...
3
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...
0
by: Linda Cacina | last post by:
Hello all you fine folks, Here is some code I am using to merge data from a single record Access 2K3 table into a NEW word document based on a pre-defined Word merge template doc. All I want to...
4
by: lesperancer | last post by:
I have 3 tables (office97) tblQuote quoteNbr tblDetails ( quote : 1 <-> M: quoteDetails) quoteNbr detailLine product value
8
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields...
1
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!)...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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...

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.