We help IT Professionals succeed at work.
Get Started

From Access 2007, Open Word Application then using Application.Quit. Getting Automation Error: The object invoked has disconnected from its clients

stillers1994 asked
Last Modified: 2012-06-27
From my Access application, using vba, I can successfully open Word, select a template, add text to bookmarks and save and close the document. The code for this is attached (minus all the filling in the bookmarks stuff)

But I can't seem to actually quit the instance of Word that I created.

I need to close word before I can then go onto attach the document I have just created to an Access attachment type field.

When I get to the line .Application.Quit
I get that lovely error...

Automation Error the object invoked has disconnected from its clients

I found most of the code for opening Word on the internet so am working a little in the dark here and any help would be so gratefully received.
Many thanks

Dim objWord As Object
   Dim appWord As Word.Application
   On Error Resume Next
    Set appWord = GetObject(, "Word.Application")
    If Err Then
            Set appWord = CreateObject("Word.Application")
             If Err Then
                  MsgBox "Can't start Word!"
                   Exit Sub
             End If
             appWord.Visible = True
      End If
    With appWord.Documents.Add(Template:="WCSQuoteTemplate")
       'move to each bookmark, and insert correct text
       .SaveAs FileName:=myfilename, FileFormat:=wdFormatDocumentDefault
    End With
   Set objWord = Nothing

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE