Section Break problem

K

khalid

I am using a VB program to do Word mail merge. The program has been working fine with NT and Word 97. Now as we started to use Window 2000 and Word 2002 (XP) I started to get Section Break problem in the main merged document.
When the program cut and paste the new merged letter into the main document, sometime it insert a Section Break(Continuous) and other times it insert a Section Break(Next page) after the merged letter. I added an "InsertBreak" command to force the new letter on the next page, but on some PCs it insert an extra blank page.

I am not able to figure out why it is happening like this. I hope I have explained my problem.

I am using following VB code:

If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2, SubType:=wdMergeSubTypeWord2000
Else
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2
End If

With WrdApp.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.Execute
End With

'Select all letters for current template in new file
WrdApp.ActiveDocument.Select
'put selection into clipboard
WrdApp.Selection.Copy
'close letter file in Word without changes
WrdApp.ActiveDocument.Close wdDoNotSaveChanges
'close template file in Word without changes
WrdApp.ActiveDocument.Close wdDoNotSaveChanges
'paste all letters merged from current template into new file
WrdApp.Selection.Paste

If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.Selection.InsertBreak ' 'Type:=wdPageBreak
End If

Thanks
Khalid
 
P

Peter Jamieson

Hi Khalid,

I don't understand why you need to create the new document, unless it is
part of your effort to solve the problem?

Instead, could you use e.g.

' Before the code you posted...
Dim MMMDoc As Word.Document ' Mail Merge Main document
Set MMMDoc = ActiveDocument

' Then use MMMDoc instead of ActiveDocument until after you Execute the
merge.


' Just close the mail merge main document

'close template file in Word without changes
WrdApp.MMMDoc.Close wdDoNotSaveChanges

....and the ActiveDocument will contain the merge results.

Sorry if that is no help.
--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

khalid said:
I am using a VB program to do Word mail merge. The program has been
working fine with NT and Word 97. Now as we started to use Window 2000 and
Word 2002 (XP) I started to get Section Break problem in the main merged
document.
When the program cut and paste the new merged letter into the main
document, sometime it insert a Section Break(Continuous) and other times it
insert a Section Break(Next page) after the merged letter. I added an
"InsertBreak" command to force the new letter on the next page, but on some
PCs it insert an extra blank page.
I am not able to figure out why it is happening like this. I hope I have explained my problem.

I am using following VB code:

If Val(WrdApp.Version) >= 10 Then ' 'Word XP
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"dsn=" & DSN & ";UID=" & UserId & ";PWD=" & Password & ";" _
, SQLStatement:=mSelection1 _
, SQLStatement1:=mSelection2, SubType:=wdMergeSubTypeWord2000
Else
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="", Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=False, AddToRecentFiles:=False, _
 
K

Khalid

Peter Jamieson! Thanks for the response.

I need another document to save the Merge results, because
I need to save all Merge results together in one document.
I have number of templates and large amount of the records.

Actually the problems occurs when the program cut and
paste the Merge results into the main document. Sometime
it is pasted with "Section Break(Continuous)" and sometime
with "Section Break(Next page)". I have no clue why this
is happening.
-----Original Message-----
Hi Khalid,

I don't understand why you need to create the new document, unless it is
part of your effort to solve the problem?

Instead, could you use e.g.

' Before the code you posted...
Dim MMMDoc As Word.Document ' Mail Merge Main document
Set MMMDoc = ActiveDocument

' Then use MMMDoc instead of ActiveDocument until after you Execute the
merge.


' Just close the mail merge main document

'close template file in Word without changes
WrdApp.MMMDoc.Close wdDoNotSaveChanges

....and the ActiveDocument will contain the merge results.

Sorry if that is no help.
--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

program has been
working fine with NT and Word 97. Now as we started to use Window 2000 and
Word 2002 (XP) I started to get Section Break problem in the main merged
document. into the main
document, sometime it insert a Section Break(Continuous) and other times it
insert a Section Break(Next page) after the merged letter. I added an
"InsertBreak" command to force the new letter on the next page, but on some
PCs it insert an extra blank page. this. I hope I have
explained my problem.
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="",
Format:=wdOpenFormatAuto, _ ReadOnly:=False,
LinkToSource:=False, AddToRecentFiles:=False, _ PasswordTemplate:="",
WritePasswordDocument:="", _ & ";PWD=" & Password & ";"
_
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="",
Format:=wdOpenFormatAuto, _ ReadOnly:=False,
LinkToSource:=False, AddToRecentFiles:=False, _ PasswordTemplate:="",
WritePasswordDocument:="", _ & ";PWD=" & Password & ";"
_
WrdApp.Selection.InsertBreak '
 
C

Cindy M -WordMVP-

Hi Khalid,
I need another document to save the Merge results, because
I need to save all Merge results together in one document.
I have number of templates and large amount of the records.

Actually the problems occurs when the program cut and
paste the Merge results into the main document. Sometime
it is pasted with "Section Break(Continuous)" and sometime
with "Section Break(Next page)". I have no clue why this
is happening.
Like Peter, I'm having difficulties understanding why you're
doing what you're doing, but since you've been using it for a
while now, we'll just have to accept that it's what you want
:)

Two thoughts about the section breaks

1. Is Word bringing across the type of section break that was
present in the merge result you're copying? You need to check
that.

2. Generally, the type of section break Word will create on
its own is controlled by the setting under File/Page
Setup/Layout/Section start. You should check whether this
might be affecting what you're seeing. Make sure it's set
correctly before you start copying and pasting.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top