MailMerge Main Docs lose Datasource Info when opened using VBA in Access.

I have a Word 2002 mailmerge document.  It has been setup with a
datasource which is a simple query inside an Access 2002 database.  When you open the
document from Word it prompts you if you want to run the query and the
mailmerge toolbar has most buttons enabled. You can execute the mailmerge right away.

If I use the following VBA code in the same Access Database to open the same
word document, it opens with nearly all mailmerge buttons Disabled.  You
are forced to relink the datasource.  

      Dim oApp As Word.Application
      Set oApp = CreateObject("Word.Application")
      oApp.Visible = True

      oApp.Documents.Open ("MailMergeMainDocument.DOC")

I have tried taking programatic control of Word with the following code, but the user is still
forced to pick the Access query 's name in a window.

    Set MyDB = CurrentDb()
    Set MyRs = MyDB.OpenRecordset("Test_takers_Mail_Merge_UNIQUE_Letters_QRY", dbOpenDynaset, dbSeeChanges)

    Dim myMerge As Word.MailMerge, MyDoc As Word.Document, ConnectStr As String
    Dim oApp As Word.Application
    If MyRs.BOF And MyRs.EOF Then
        MsgBox "There are no test score records matching your criteria which have the Letter_to_Send field filled."
      Set oApp = CreateObject("Word.Application")
      oApp.Visible = True
      While Not MyRs.EOF
         oApp.Documents.Open (MyRs.Fields("Letter_to_Send"))
         Set MyDoc = oApp.ActiveDocument
         Set myMerge = MyDoc.MailMerge
         ConnectStr = "Query " & DLookup("MailMergeQuery", "RA_Letter_Types", "[Doc Name of letter]=""" & MyRs.Fields("Letter_to_Send") & """")
         With myMerge
             .MainDocumentType = wdFormLetters
             .OpenDataSource Name:="C:\USSAIL\USSAILSQ.MDB", _
             ReadOnly:=True, _
             LinkToSource:=True, AddToRecentFiles:=False, _
             Connection:=ConnectStr, OpenExclusive:=False
             Debug.Print MyDoc.Name, Str(myMerge.MainDocumentType), Str(wdNotAMergeDocument), Str(wdFormLetters)
             If myMerge.State = wdMainAndDataSource Or myMerge.State = wdMainAndSourceAndHeader Then myMerge.Execute
         End With
    End If
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joanne M. OrzechManager, Document Services CenterCommented:
AndyMagruderAuthor Commented:
I found the answer to my own problem on Experts Exchange. It's under Visual Basic, Q_20514447.html .  Word now runs the mailmerge straight away with no prompts.

Refering to Q_20514447.html, the exact line of code that made the difference is:


In Q_20514447.html there's also some code that lets the VB determine what version of office Word is. My problem seems to happen when using Word 10 (Office XP/ 2002)

Joanne M. OrzechManager, Document Services CenterCommented:
No problem
Closed, 500 points refunded.

Community Support Moderator
Experts Exchange

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.