JayGoettelmann
Programmer
After being stumped by calling Word’s Mail Merge from Access (Office XP. There is no problem in Office 2000), I have written code to copy a word document including bookmarks to a new document then inserting data via code. This works about 25 percent of the time. Other times I’m getting Error 462 Remote server does not exist or is unavailable. I’m guessing that the code is running faster than the automation tasks. I’ve tried inserting loops that call the DoEvents function and DBEngine.idle method to no avail. Any ideas?
<Code>
Dim objWord As Object
Dim objDoc As Word.Document
Dim objNewDoc As New Word.Document
Dim WordNotRunning As Boolean
DoCmd.Hourglass (True)
On Error Resume Next
Set objWord = GetObject(, "Word.Application"
If Err.Number <> 0 Then WordNotRunning = True
Err.Clear
If WordNotRunning Then
Set objWord = New Word.Application
End If
'Turn error catch back on
On Error GoTo Err_Catch
Set objDoc = GetObject("C:\MyContract.doc"
objDoc.Select
'The error usually occurs here
objWord.Selection.Copy
objNewDoc.Bookmarks("\StartofDoc".Select
objWord.Selection.Paste
With objNewDoc.PageSetup
.LeftMargin = InchesToPoints(0.7)
.RightMargin = InchesToPoints(0.7)
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
End With
objDoc.Close
</Code>
Thanks a lot,
Jay
<Code>
Dim objWord As Object
Dim objDoc As Word.Document
Dim objNewDoc As New Word.Document
Dim WordNotRunning As Boolean
DoCmd.Hourglass (True)
On Error Resume Next
Set objWord = GetObject(, "Word.Application"
If Err.Number <> 0 Then WordNotRunning = True
Err.Clear
If WordNotRunning Then
Set objWord = New Word.Application
End If
'Turn error catch back on
On Error GoTo Err_Catch
Set objDoc = GetObject("C:\MyContract.doc"
objDoc.Select
'The error usually occurs here
objWord.Selection.Copy
objNewDoc.Bookmarks("\StartofDoc".Select
objWord.Selection.Paste
With objNewDoc.PageSetup
.LeftMargin = InchesToPoints(0.7)
.RightMargin = InchesToPoints(0.7)
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
End With
objDoc.Close
</Code>
Thanks a lot,
Jay