• OPen Wrod merge doc from Access vba

    Author
    Topic
    #470538

    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_HiresLetters”
    strDoc = gStrDocPath & strLetterName

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

    Allan

    Viewing 3 reply threads
    Author
    Replies
    • #1235697

      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.

    • #1235780

      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_HiresLetters"
              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

    • #1235981

      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
      
      
    • #1236057

      I thought about that, and I’ll give it a try.

      Thanks for the reply,
      Allan

    Viewing 3 reply threads
    Reply To: OPen Wrod merge doc from Access vba

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: