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.Applicatio n
Dim strDocumentPath As String
Set db = CurrentDb()
Set objWord = GetObject(, "Word.Applicati on")
If Err.Number <> 0 Then
Set objWord = CreateObject("W ord.Application ")
End If
objWord.Visible = True
strMyTemplatePa th = "C:\Users\Bill\ Documents\Datab ases\Documents\ ACP117Section2. dot"
objWord.Documen ts.Add Template:=strDo cumentPathPath, NewTemplate:=Fa lse
objWord.ActiveD ocument.MailMer ge.OpenDataSour ce _
Name:=db.Name, _
LinkToSource:=T rue, _
Connection:="QU ERY QryACP117Sect2" , _
SQLStatement:=" Select * from [QryACP117Sect2]"
objWord.ActiveD ocument.MailMer ge.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.
3 2155 FishVal 2,653
Recognized Expert Specialist
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.MainD ocumentType property.
Hi, Fish
I can't thank you enough. I simply added the line:
objWord.ActiveD ocument.MailMer ge.MainDocument Type = wdDirectory
and it works a treat. Once again many thanks
HarryTheB
FishVal 2,653
Recognized Expert Specialist
Not a problem.
Good luck.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 to output a new
Word .doc file with the template filled in with the record I've
generated.
(To refresh your memory, in Word a mailmerge is achieved by a) under
Tools -> Letters and Mailings, check off Show Mail Merge Toolbar; b)
open a document...
|
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 to get different percentages
of that total amount on my document. For example, display 10% of that
amount. I am not too familiar with using field codes and have only used them
a couple of times in the past. I'm currently doing this with Word 2000....
|
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 each person for whom a mail
merge letter is desired.
The query reads address info from the table for each record where is
true.
|
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 displays and the user saves it or
whatever, then closes it, the actual merge template is displayed in
the background and asks if the user wants to save the updated merge
document. I do not want the user to even be aware of the merge
template at all. ...
|
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 document in Word;
2. opens the document and runs the merge process for the new data.
I have managed to write the code to perform step 1 ok, but I'm having
trouble with step 2. It opens the word document fine but does not perform
the mail merge of...
| |
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 happen is as follows:
User defines a storage path and name for the new Word document then
clicks a "Create" button on a form. From that point on I use the
following code:
|
by: lesperancer |
last post by:
I have 3 tables (office97)
tblQuote
quoteNbr
tblDetails ( quote : 1 <-> M: quoteDetails)
quoteNbr
detailLine
product
value
|
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 from
Access are automatically filled into the Word document. The query
could be anywhere from 0-5000 names, one cover letter per name. AND to
this cover letter for each applicant, there has to be attached a two
page document. How in the world can...
|
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!) upgraded from Access 2000 to Access 2007. Now that component is failing.
The merge is building the data source file fine (text file named merge.888).
I am providing an absolute path reference to the word file being used for the mail merge. ...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |