Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    merging to Word From Access 97 (Access 97/Word 6.0)

    I got Helen Feddema's "Access Archon" column #44 and was able to set up a situation where a user enters a new work request, and the data they enter turns into an email with an attached word document that is created via merging this data to a .dot template. I'm all excited about it except for one thing - Word stays open. Any suggestions as to the code I can put in to close the session?

    Here's sort of my code (I copied some of Helen's):

    Set objWord = GetObject(, "Word.Application")
    If Err.number = 429 Then
    'Word is not running; creating a word object
    Set objWord = CreateObject("Word.Application")
    .......
    some code is run to gather data
    ................
    objWord.Selection.WholeStory
    objWord.Selection.Fields.Update
    objWord.Selection.HomeKey Unit:=6
    objWord.Visible = True
    objWord.Activate
    ................................
    this creates the form and opens the document
    some more code goes here to send the email
    .......................................
    objWord.ActiveDocument.SaveAs strSaveNamePath
    objWord.ActiveDocument.Close
    ......................................
    this is saving and closing the document

    .....what I'm left with is an open Word window with nothing in it. I can't figure out the magic words to close the window.

    Help!
    Carpy Diem, it's .

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: merging to Word From Access 97 (Access 97/Word 6.0)

    You might want to look at the current column (#92) in Woody's Access Watch which talks about automation and mail merges, and also look at the Automation Help file that can be downloaded from Microsoft in article Q302460.

    I think you basically need to see objWord to be nothing, i.e.

    Set appWord = Nothing

    Word 97 behaves a little differently than 2000/2002, as it hangs around even if you've closed all the documents - you can also be affected by using WordMail. Hope this helps.
    Wendell

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: merging to Word From Access 97 (Access 97/Word 6.0)

    I had looked at the current column, which led me to the old one. I'll look at the Q302460 and also try that set appWord = nothing.

    Thanks for your help!
    Carpy Diem, it's .

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: merging to Word From Access 97 (Access 97/Word 6.0)

    Try objWord.Quit after the document is closed. Then set objWord to nothing in your Access code to destroy the object variable.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: merging to Word From Access 97 (Access 97/Word 6.0)

    It works! I got it to create the attachment, attach it to the email, send it on its way, kill the created document and close Word!

    Now, if it would only get me a cup of coffee and take out the trash......just kidding, of course.


    Thanks Wendell and Charlotte!
    Carpy Diem, it's .

Posting Permissions

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