By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,863 Members | 879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,863 IT Pros & Developers. It's quick & easy.

Help With Merge to A Word Document

P: 3
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"

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

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

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
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 2,653
Hi, HarryTheB.

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


P.S. I guess in your case you should set MailMerge.MainDocumentType property.
Jan 14 '08 #2

P: 3
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

Jan 14 '08 #3

Expert 2.5K+
P: 2,653
Not a problem.
Good luck.
Jan 14 '08 #4

Post your reply

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