X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Word Mail Merge Page Break Problem With Catalog/directory, Access 2016    
post Oct 20 2017, 01:12 PM

Posts: 39
Joined: 26-October 05

Hello and thanks for reading,

My mail merge problem is about format. My primary document (in Word) is a Directory (I believe this used to be called a Catalog) because I don't want page breaks between entries. When I do the merge from Word, it looks great -- no page breaks except for length.

My Access DB has some simple code (copied below) that works great, EXCEPT I get page breaks between entries. I tried to see if there was an option to the Execute method that would be specific for a directory, but there doesn't seem to be. Any ideas how I can make the code reproduce what I get when I do the merge "manually?"

Here's the VBA code:

Private Sub OpenMergedDoc(strTemplate As String, strMergedDocName As String, strSource As String)
'code found at http://www.tek-tips.com/faqs.cfm?fid=3237
On Error GoTo Err_OpenMergedDoc

'opens an instance of Word, opens a merge template which has its data source
'already linked to a query in the database,
'merges the template to a new document,
'saves the merged file with a descriptive name,
'then closes the merge template

Dim objWord As New Word.Application
Dim objDoc As Word.Document
objWord.Application.Visible = True
Set objDoc = objWord.Documents.Open(strTemplate)

'Make Word visible so that if any errors occur,
'you can close the instance of Word manually
objWord.Application.Visible = True

'Merge to a new document
objDoc.MailMerge.OpenDataSource _
Name:=strSource, _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY qryFilteredProjects", _
SQLStatement:="SELECT * FROM [qryFilteredProjects]"

objDoc.MailMerge.Destination = wdSendToNewDocument
objWord.Application.Documents(1).SaveAs (strMergedDocName & ".docx")

'close the merge template without saving
objWord.Application.Documents(2).Close wdDoNotSaveChanges

'release the variables
Set objWord = Nothing
Set objDoc = Nothing

Exit Sub

MsgBox Err.Description, vbExclamation, "Error in OpenMergedDoc"
Resume Exit_OpenMergedDoc

End Sub
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    21st July 2018 - 04:21 PM