Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2004

Tip: Looking for answers? Try searching our database.

Section Break problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
khalid - 03 Feb 2004 15:01 GMT
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
Peter Jamieson - 04 Feb 2004 10:52 GMT
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/

> 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.
>
[quoted text clipped - 46 lines]
> Thanks
> Khalid
Khalid - 04 Feb 2004 15:47 GMT
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,
[quoted text clipped - 40 lines]
>>    If Val(WrdApp.Version) >= 10 Then                      ' 'Word XP
>>          
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="",
>Format:=wdOpenFormatAuto, _
>>                ConfirmConversions:=False, ReadOnly:=False,
[quoted text clipped - 10 lines]
>>      Else
>>          
WrdApp.ActiveDocument.MailMerge.OpenDataSource Name:="",
>Format:=wdOpenFormatAuto, _
>>                ConfirmConversions:=False, ReadOnly:=False,
[quoted text clipped - 31 lines]
>>      If Val(WrdApp.Version) >= 10 Then                      ' 'Word XP
>>          
WrdApp.Selection.InsertBreak                      '
>'Type:=wdPageBreak
>>      End If
[quoted text clipped - 3 lines]
>
>.
Cindy M  -WordMVP- - 04 Feb 2004 18:49 GMT
Hi Khalid,

> I need another document to save the Merge results, because
> I need to save all Merge results together in one document.
[quoted text clipped - 5 lines]
> 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 :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.