dougjack10
Technical User
I am trying to automatically save a word mail merge documents that has been generated from access.
I have generated some code that;
1. Opens the mail merge documents,
2. It then merges the mail merge documents to a new document based on a record in an access database.
3. We then go back to the mailmerge.docx and close it.
4. That leaves the merged documents open, and I am trying to automatically save.
When I try and save the merged document that is open, I get the following error above.
Automaton error, The object invoked was disconnected from the client. I have also received a general object error.
Code:
'objWord.ActiveDocument.SaveAs ("C:\Users\" & Me.Sitename & "_" & Me.ownername & ".docx")
When I use my bookmark merge from access it does save; and the code above works. Although it does not work with the mail merge code, the problem appears to be that the word document does not seem to have focus. In the bookmark example I open the document, and then save it. With the mailmerge you have two word documents.
Code:
Dim strSQL As String
Dim strOldSQL As String
strSQL = "SELECT IDoptionpayments FROM TBL_owneroptionpayments " & _
"WHERE IDoptionpayments=" & [Forms]![frm_ladnownerpayments]![IDoptionpayments]
strOldSQL = fChangeSQL("qry_landownerpayments2", strSQL)
Dim stDocName As String
On Error GoTo Err_Command235_Click
Dim WordObj As Word.Application
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open ("C:\Users\ Paymentsinvoice_mailmerge.docx")
WordObj.Visible = True
With WordObj
.ActiveDocument.MailMerge.Execute
End With
With WordObj
Set WordDoc = .Documents.Open("C:\Users\Paymentsinvoice_mailmerge.docx")
End With
With WordDoc
.Close savechanges:=False
End With
'----------------------------
[COLOR=#CC0000] With WordDoc
.Visible = True
Set wrdDoc = WordApp.Documents.Open(WDoc)
.SaveAs ("C:\Users\" & Me.Sitename & "_" & Me.ownernameontitle & ".docx")[/color]
End With