abbaddon223
Registered User.
- Local time
- Yesterday, 21:10
- Joined
- Mar 13, 2010
- Messages
- 162
Hi,
I'm hoping someone can help me please?
I have a word doc (2010) which is connected to an access DB (2010) for a mail merge. The mail merge has already been done from word to access, then I'm just using a vba call from access to open the word doc.
When I run the command the first time round, it opens, prints and closes just fine.
If I run it again, I get the following error: "Run time error 462. The remote machine does not exist or is unavailable" and it debugs at the following section of the code: "Set myMerge = ActiveDocument.MailMerge"
From looking about apparently the below code is not "Releasing" the word document properly, so when it goes to run again, it errors. That said, if that is the issue, I don't know how to modify the below. Can anyone help me please? It would be really appreciated!!
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "D:\Remote Applications\AIA Invoice Management\Mail_Merges\Bulk Merges\8 - 14 Days Chase Letter.docx"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 100000
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
oApp.ActiveDocument.Close
oApp.Quit
End If
I'm hoping someone can help me please?
I have a word doc (2010) which is connected to an access DB (2010) for a mail merge. The mail merge has already been done from word to access, then I'm just using a vba call from access to open the word doc.
When I run the command the first time round, it opens, prints and closes just fine.
If I run it again, I get the following error: "Run time error 462. The remote machine does not exist or is unavailable" and it debugs at the following section of the code: "Set myMerge = ActiveDocument.MailMerge"
From looking about apparently the below code is not "Releasing" the word document properly, so when it goes to run again, it errors. That said, if that is the issue, I don't know how to modify the below. Can anyone help me please? It would be really appreciated!!
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "D:\Remote Applications\AIA Invoice Management\Mail_Merges\Bulk Merges\8 - 14 Days Chase Letter.docx"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 100000
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
oApp.ActiveDocument.Close
oApp.Quit
End If