Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word '02 MailMerge problem 1

Status
Not open for further replies.

guido45

IS-IT--Management
Apr 8, 2003
18
0
0
GB
Hi
I have a strange problem in Word when doing a MailMerge on one of our pc's (the process works fine on all others...).
I have these two merges which need to be run fairly regularly:

Code:
Public Sub AccxIR35()
Dim ans

WordBasic.Shell "s:\bc\BAX.bat"
ans = WordBasic.MsgBox("Merge Contracts?", 3)
If ans = 0 Or ans = 1 Then GoTo Bye

    Documents.Open FileName:="S:\WP\CONTRACT\ir35accx.rtf", ConfirmConversions:=False, ReadOnly _
        :=True, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .Execute
    End With
    Windows("ir35accx (Read-Only)").Activate
    ActiveDocument.Close wdDoNotSaveChanges

Bye:
End Sub

Code:
Public Sub ClientContract()
Dim ans

WordBasic.Shell "s:\bc\C-Clet.bat"
ans = WordBasic.MsgBox("Merge Client Contracts?", 3)
If ans = 0 Or ans = 1 Then GoTo Bye

    Documents.Open FileName:="S:\WP\CONTRACT\CLIENT.DOC", ConfirmConversions:=False, ReadOnly _
        :=True, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .Execute
    End With
    Windows("CLIENT.DOC (Read-Only)").Activate
    ActiveDocument.Close wdDoNotSaveChanges

Bye:
End Sub

which as you can see are basically the same but merge with different data sources.
Problem is, if the user runs one of them and then the other, the second one appears to ignore the merge command and so we end up with just the template. The only way around this is to reboot the system.
If we then try the merge from any other pc, it will work fine!

The system is WindowsXP SP2, Office 2002 (with most recent updates) and is the same as most of our other workstations.

Please help, this is driving me mad!!

 
1. What is the .bat file doing??? This may, or may not, affect the following....

2. You state "one" then the "other". Does it make a difference WHICH is run first? Does it mess up running the RTF file first, but NOT mess up running the DOC file first?

3. If you are using XP and OfficeXP (2002), why are you using WordBasic syntax, as in "WordBasic.MsgBox("Merge Client Contracts?", 3)" ? Bleech.

4. make your documents objects. This will help keep the documents explicitly isolated from each other.
Code:
Dim MainDoc As Document
Documents.Open FileName:="S:\WP\CONTRACT\CLIENT.DOC"
  Set MainDoc = ActiveDocument
  With MainDoc.MailMerge
     .Destination = wdSendToNewDocument
     .Execute
  End With
  MainDoc.Close wdDoNotSaveChanges
  Set MainDoc = Nothing

Gerry
See my Paintings and Sculpture
 
The .bat file gets the database to output the data (.txt) file.

It seems to make no difference which one is run first, and apparently it isn't always the second one which ggoes wrong, it can be third or fourth...

These scripts were written some time ago (not by me) for an earlier edition of Word - I really don't know anything about the correct syntax to use so I'm unable to update them!

Thanks for your help!
 
Code:
Public Sub AccxIR35()
Dim ans
Dim RetVal
Dim MainDoc As Document
' run the batch file hidden
RetVal = Shell("s:\bc\C-Clet.bat",0)

ans = MsgBox("Merge Contracts?", vbYesNo)
If ans = vbYes Then
  Documents.Open FileName:="S:\WP\CONTRACT\ir35accx.rtf"
  Set MainDoc = ActiveDocument
  With MainDoc.MailMerge
     .Destination = wdSendToNewDocument
     .Execute
  End With
  MainDoc.Close wdDoNotSaveChanges
  Set MainDoc = Nothing
End If
End Sub

Essentially if they answer No, even in your old code, it simply exits. Bye: justs exits. Are there any consequences to think of running the .BAT file, and then do nothing else? Try running it with each document isolated as objects and see if it does the same thing.

Gerry
See my Paintings and Sculpture
 
Thank you very much. I will try with the new and improved version and see if we still get any hiccups!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top