Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automation error opening word doc from access

Status
Not open for further replies.

bwilkens

Programmer
Feb 4, 2002
7
US
I have a word document that I am merging data into from access. The first time I can open and merge data fine, but if the user closes the word doc, I get an automation error when I try to reopen it the second time for another merge. If I restart access, no problem.

Here is my code.
Public Function OpenCatalog()

'Start Word and get template info
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
objWord.Application.Visible = True
Err.Clear
'this is a template I copy bookmarks from
objWord.Documents.Add Template:=strTemplPath & "Merge1.dot"
'the automation error occurs on the next line the second time although word is opened and the template appears
ActiveDocument.Range.Copy
ActiveDocument.Close
'open my current catalog.doc
objWord.Documents.Open (strTemplPath & "catalog.doc")
AppActivate "Microsoft Word", 1
'go to the end and paste bookmarks
Set myrange = ActiveDocument.Range(Start:=ActiveDocument.Content.End - 1, End:=ActiveDocument.Content.End - 1)
myrange.Paste

ElseIf Err.Number <> 0 Then
MsgBox Err.Number & Err.Description & &quot;An unexpected error has occurred.&quot;
Exit Function
Else 'doc is still open

Set myrange = ActiveDocument.Range(Start:=ActiveDocument.Content.End - 1, End:=ActiveDocument.Content.End - 1)
myrange.Paste
End If

End Function

after I do the merge I open the catalog to review the additions as follows:


With objWord.ActiveDocument
.Fields.Update
End With


ActiveDocument.Save
AppActivate &quot;Microsoft Word&quot;, 1


Set objWord = Nothing
end sub

Any ideas would be greatly appreciated!
Beth

 
Dear Jay,

Unfortunately I never did figure it out. Have been working on another project since May but will be getting back to this one in a month or so. Will let you know if I discover anything and if you come up with any thoughts, please let me know. Thanks.

Beth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top