Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jan 2005
    Location
    Sydney, New South Wales, Australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mail merge to Word (2002)

    G'day,

    thank you for the enormous help you have given in the past. I hope you can sort this one out for me.
    I want to merge data from an Access 2002 table into a new word document, based on a template.

    To make this easy for the user, I have automated the process as far as possible.

    The user executes the code below by clicking on a button.

    Dim wdApp As Object

    ' Create Word Application Object
    Set wdApp = CreateObject("Word.Application")

    ' Create new mail merge letter based on skeleton
    wdApp.Documents.Add Template:=Parish2002_PATH & "MemberFamiliesSkeleton.doc", NewTemplate:=False, DocumentType:=0

    'Make Word visible through the Application object.
    wdApp.Application.Visible = True

    Word is opened and in turn creates a new document (document1) based on "MemberFamiliesSkeleton.doc".
    So far so good!

    The problem is that the new document is not connected to the table in the database!!!

    Interestingly, if I open Word and use file/new to create a document based on my template, the new file is connected to the database.

    (Note: I know that the "template" is a .doc file. It is really being used as a skeleton and has never before caused problems being used in this manner.)

    Are there parameters that can be passed when creating a document from within access or some other method of controlling this situation?

    Regards and thanks to all, Terry

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Mail merge to Word (2002)

    You don't need to make a new document using your document as a template.
    All you need is to open that document, then perform a merge to a new document, then close the master.

    wdApp.Documents.Open filename:=Parish2002_PATH & "MemberFamiliesSkeleton.doc"
    wdApp.Application.Visible = True
    wdApp.Activedocument.MailMerge.Destination = wdSendToNewDocument
    wdApp.activedocument.mailmerge.execute
    wdApp.Documents(Parish2002_PATH & "MemberFamiliesSkeleton.doc").Close SaveChanges:=wdDoNotSaveChanges

    Try the above. I am modifying some code I use on the fly, so I have not tested it as written above.
    Regards
    John



  3. #3
    New Lounger
    Join Date
    Jan 2005
    Location
    Sydney, New South Wales, Australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mail merge to Word (2002)

    Thank you for your suggestion John. Unfortunately your code has the same problem as mine: when Word has created the new document, using the template, the Mail Merge toolbar is mostly disabled, indicating that the link to the database does not exist
    I received a runtime error and had to comment out line 3:-
    wdApp.Activedocument.MailMerge.Destination = wdSendToNewDocument
    This also indicates that it is not recognised as a Mail Merge document.
    I also added two lines at the top of the code:-
    Dim wdApp As Object
    ' Create Word Application Object
    Set wdApp = CreateObject("Word.Application")
    wdApp.Documents.Open FileName:=Parish2002_PATH & "Member Families Skeleton.doc"
    wdApp.Application.Visible = True
    'wdApp.activedocument.mailmerge.Destination = wdSendToNewDocument
    wdApp.ActiveDocument.MailMerge.Execute
    wdApp.Documents(Parish2002_PATH & "Member Families Skeleton.doc").Close SaveChanges:=wdDoNotSaveChanges
    I am continuing to research this problem. Any additional help would be greatly appreciated, Terry

  4. #4
    New Lounger
    Join Date
    Jan 2005
    Location
    Sydney, New South Wales, Australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mail merge to Word (2002)

    I have a workaround which solves the problem.
    The solution can be found in:- http://support.microsoft.com/kb/825765
    Service Pack 3 for Office 2002 prevents the link from being made.
    The workaround edits the Registry so that the security feature is disabled.
    If anyone knows of a solution that does not compromise security, I would appreciate this information.
    John, thank you for your help, Terry

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Mail merge to Word (2002)

    I am glad you found the solution.

    I always remove the data source from the Word document after I have set up the merge fields, so the document reverts to just a plain Word document.
    I then reattach the data source in code, after opening the document, when I perform the merge. This makes the document easy to edit later as it does not need to connect to the database.
    This may be why I do not see this problem.
    Regards
    John



  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Mail merge to Word (2002)

    I attach a little example that works for me without any warnings. There is a little db, and a word doc. Unzip them both to the same folder, then open the db.
    I have used 2003, so you will need to correct the Reference to word 11.
    Attached Files Attached Files
    Regards
    John



  7. #7
    New Lounger
    Join Date
    Jan 2005
    Location
    Sydney, New South Wales, Australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mail merge to Word (2002)

    Thank you John.
    I have test run your code and it works fine after changing the reference to Office11
    My original code now works as well because I have changed the Registry.
    Over the weekend I shall test your code on another PC that does not have the Registry fix.
    I'll let you know what transpires. If your code works without the fix, it is definitely preferable.
    Thanks for the help, Terry

  8. #8
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Mail merge to Word (2002)

    I will be interested to know what happens. I use similar code in lots of dbs that are used by lots of people, and no-one ever seems to get security warnings.
    It is hard to believe they have all modified their registries, or not applied Service packs.
    Regards
    John



Posting Permissions

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