Link to home
Start Free TrialLog in
Avatar of stillers1994
stillers1994

asked on

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

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
            Err.Clear
            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
       .Close
       .Application.Quit
    End With
 
   Set objWord = Nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rowansmith
rowansmith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stillers1994
stillers1994

ASKER

Many thanks
Perfectly obvious solution
Which is why I so need this EE membership!
So is this problem now resolved?  Is everything now working for you?
So sorry for the delay in acceptance - I thought I already had but obviously messed up the procedure
Many thanks