additional copy of document is generated

M

Marty

Hi-

I have a mailmerge template in Word2003 which uses MS Visual Basic macros.
These macros ask for data input which is used to populate the template. After
the document is generated, there is a second copy. Why am I getting 2
documents?

I have other similar templates which work correctly by producing only 1
document.

Thanks,
Marty
 
D

Doug Robbins - Word MVP

It is not possible to tell without your showing us the code that is being
run.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter Jamieson

Maybe you could spell out a few more things - e.g., is your "template" a
..dot or a .doc? Are the macros VB or VBA? What is "generating" the document?
Are you talking about the process where you use File|New to create a new
document from a tempalte, or the process where you are performing a
mailmerge

It really isn't clear what you are doing and what you expect to happen as a
result - remember, we can't see your template, its macros, and so on.

Peter Jamieson
 
M

Marty

Peter-

It is a .dot When I open the macros it just says "MS Visual Basic" on top,
so I am not sure if it is VB or VBA (how do I tell the difference?)

When I delete about 99% of the bottom of the template, then run the
mail-merge macros, I get only 1 copy. I'm trying to see at what point it
gives me a second copy of the document.

I thought that it was because I had a section break, but apparently this is
not the cause.

Here is the code that produces the finished document:

WordBasic.MailMergeMainDocumentType 0
WordBasic.MailMergeOpenDataSource Name:="", ConfirmConversions:=0,
ReadOnly:=0, LinkToSource:=0, AddToMru:=0, PasswordDoc:="", PasswordDot:="",
Revert:=0, WritePasswordDoc:="", WritePasswordDot:="",
Connection:="DSN=NCR-SQL;UID=sa;PWD=;APP=Microsoft
Query;WSID=SHIVAINDRA;LANGUAGE=us_english;DATABASE=lp_patents",
SQLStatement:="execute splp_lppci_US " & Chr(34) & OrderLetterNumber &
Chr(34), SQLStatement1:=""
WordBasic.MailMerge CheckErrors:=1, Destination:=0, MergeRecords:=0,
From:="", To:="", Suppression:=0, MailMerge:=1, MailSubject:="",
MailAsAttachment:=0, MailAddress:=""

Then I check some inputted variables to see if I need to delete any parts of
the document:


If LPPCI0.AddedPages.Value <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With
End If

If LPPCI3.OptionButton17 <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With
End If

With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[transmittal]"
.Delete
End With

With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With

With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[cover sheet]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With



Thanks,
Marty
 
P

Peter Jamieson

so I am not sure if it is VB or VBA (how do I tell the difference?)

From that description, it's VBA.
When I delete about 99% of the bottom of the template, then run the
mail-merge macros, I get only 1 copy. I'm trying to see at what point it
gives me a second copy of the document.

From that description, my best guess is that there is some corruption in the
template. And that really is a guess. Does it contain a /lot/ of macros?
Perhaps more than your other templates that work? Either way, it may be
worth trying to reconstitute your template from scratch if possible. I think
you should be able to export the macros from the VB Editor and re-import
them in a new version of the template.

I don't think the code in your macro is particularly relevant - if it's
similar to the code in macros in your other documents then it's probably
irrelevant. But I'd be interested to know whether your other merge documents
all use an execute command in their OpenDataSource method call, and whether
they also use the WordBasic object or have been converted to native VBA.

(That may be a handful to answer, but do your best!)

Peter Jamieson

Marty said:
Peter-

It is a .dot When I open the macros it just says "MS Visual Basic" on
top,
so I am not sure if it is VB or VBA (how do I tell the difference?)

When I delete about 99% of the bottom of the template, then run the
mail-merge macros, I get only 1 copy. I'm trying to see at what point it
gives me a second copy of the document.

I thought that it was because I had a section break, but apparently this
is
not the cause.

Here is the code that produces the finished document:

WordBasic.MailMergeMainDocumentType 0
WordBasic.MailMergeOpenDataSource Name:="", ConfirmConversions:=0,
ReadOnly:=0, LinkToSource:=0, AddToMru:=0, PasswordDoc:="",
PasswordDot:="",
Revert:=0, WritePasswordDoc:="", WritePasswordDot:="",
Connection:="DSN=NCR-SQL;UID=sa;PWD=;APP=Microsoft
Query;WSID=SHIVAINDRA;LANGUAGE=us_english;DATABASE=lp_patents",
SQLStatement:="execute splp_lppci_US " & Chr(34) & OrderLetterNumber &
Chr(34), SQLStatement1:=""
WordBasic.MailMerge CheckErrors:=1, Destination:=0, MergeRecords:=0,
From:="", To:="", Suppression:=0, MailMerge:=1, MailSubject:="",
MailAsAttachment:=0, MailAddress:=""

Then I check some inputted variables to see if I need to delete any parts
of
the document:


If LPPCI0.AddedPages.Value <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With
End If

If LPPCI3.OptionButton17 <> True Then
With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With
End If

With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[transmittal]"
.ExtendMode = True
.Find.Execute FindText:="[transmittal]"
.Delete
End With

With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[added pages]"
.ExtendMode = True
.Find.Execute FindText:="[added pages]"
.Delete
End With

With Selection
.HomeKey Unit:=wdStory
.Find.Execute FindText:="[cover sheet]"
.ExtendMode = True
.Find.Execute FindText:="[cover sheet]"
.Delete
End With



Thanks,
Marty


Peter Jamieson said:
Maybe you could spell out a few more things - e.g., is your "template" a
..dot or a .doc? Are the macros VB or VBA? What is "generating" the
document?
Are you talking about the process where you use File|New to create a new
document from a tempalte, or the process where you are performing a
mailmerge

It really isn't clear what you are doing and what you expect to happen as
a
result - remember, we can't see your template, its macros, and so on.

Peter Jamieson
 

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