Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Dec 2000
    Location
    Hellertown, Pennsylvania, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a Word merge document that is linked to an Access table. If I open the Word document through Word (File, Open) the data source is linked. However, when I open using code in Access the data source is not linked. Should I be adding something here to make the Access table maintained in the link?

    gStrDocPath = "S:\New_Hires\Letters\"
    strDoc = gStrDocPath & strLetterName

    Set WordDoc = WordApp.Documents.Open(gStrDocPath & strLetterName)

    Allan

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    There are a number of factors which can complicate Word merges driven by Access. One is the version of Access and Word - there were substantial changes made in the Merge process in Word 2002. Another is whether you use ODBC (OLE DB) data connections or DDE. A third is whether or not you are using Access User Security. I presume there is more code than what you have posted in your procedure that initiates the session with word, and that you are using Automation to do that. A couple of resources you might find useful are Word won't save mailmerge data connection and our tutorial Managing Merges with Access. Post back and let us know how you fare.
    Wendell

  3. #3
    Star Lounger
    Join Date
    Dec 2000
    Location
    Hellertown, Pennsylvania, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply, Wendell. You're correct, there is more code. I have a Word 2003 document that gets the merge data from an Access 2003 table. The client needs to edit the wording in the merge document on occasion, so I would like to have a command button that would open the merge document. I've written the code, the document opens, but the data source is not linked. However, if I open the merge document from the File Open menu in Word 2003, I receive the warning about the SQL command and answer Yes to the prompt.

    I'm curious why I don't receive the warning when using the VBA code. I have a Select Case statement that determines which merge letter (there is more than one) the user selected in an option group and passes the document name to the strLetterName variable.

    Code:
     
           On Error Resume Next
            MsgBox "Be sure to save document after editing", vbInformation, gcTitle
            Set WordApp = GetObject(, "Word.Application")
    
            If WordApp Is Nothing Then
                Set WordApp = CreateObject("Word.Application")
            End If
            WordApp.Visible = True
            
            gStrDocPath = "S:\New_Hires\Letters\"
            strDoc = gStrDocPath & strLetterName
          
            
            Set WordDoc = WordApp.Documents.Open(gStrDocPath & strLetterName)
    Just curious. If I cannot fix this I'll have the client open the letter through the Word File menu.

    Thanks again!
    Allan

  4. #4
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Once you have opened the word doc like this,
    can you not just set the merge source in the next line?

    Code:
    '... Code to Open Word....
    
    With Worddoc.MailMerge
          .OpenDataSource Name:="Path to Access DB", SQLStatement:="Query used in the Merge Document"
    End With
    
    '..... Carry on with your code
    Andrew

  5. #5
    Star Lounger
    Join Date
    Dec 2000
    Location
    Hellertown, Pennsylvania, USA
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thought about that, and I'll give it a try.

    Thanks for the reply,
    Allan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •