I have set up a Word mail merge document of the type Directory which
allows me to display all of the records on a single page rather than
putting each record on a separate page. It uses a temporary table in
MS Access as its datasource (loaded via a Make Table query). If I
create the temporary table and then open the mail merge document from
within MS Word and click "Merge to New Document", the information from
the temporary table is displayed in the table that I have set up. The
table looks normal with all rows on the same page.
If I use VBA to launch Word and open the same document, the data
appears but there is a section break between each row of the table. If
I want the table all together on the page, I have to manually delete
all of the section breaks. Can anybody tell me why the section breaks
are being inserted when they are clearly not in the original document?
The code that I am using is pretty standard. I am passing strTableName
as a parameter to the procedure.
Dim wrkDefault As Workspace
Dim WordDoc As Object
Dim WordApp As Object
Dim db As Database
Set db = CurrentDb
Set wrkDefault = DBEngine.Workspaces(0)
' open up word with the Mail Merge document, using the path that we
found
' with the File Open dialogue box above.
Set WordApp = CreateObject("word.application")
Set WordDoc = WordApp.Documents.Open(strInputFileName)
WordDoc.Application.Visible = True
WordDoc.MailMerge.OpenDataSource Name:=db.Name, LinkToSource:=True,
Connection:="TABLE " & strTableName, SQLStatement:="SELECT * FROM [" &
strTableName & "]"
Set db = Nothing
Thanks for any help you may have,
Sheila