M
MSU Sptn2
I have some code that opens Word and fills in the bookmarks with data from an
Access form. Everything has been working fine until today when I get this
error message: "Automation error, the server threw an exception." The
beginning of my code is pasted below. It seems to open the Word application,
but not the document. Is there a reference that I am missing?
Private Sub Contracts_Click()
On Error GoTo Err_Contracts_Click
Dim objWord As Word.Application
Dim JobHolder As String
Dim PhaseHolder As String
Dim BMRange As Range
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("Z:\ODDForms1.doc")
Set BMRange = objWord.ActiveDocument.Bookmarks("PIC").Range
If [Form_ODDAPP FORM].PIC <> "" Then
BMRange.Text = (CStr([Form_ODDAPP FORM].PIC))
Else
BMRange.Text = (CStr(""))
End If
Set BMRange = objWord.ActiveDocument.Bookmarks("Risk").Range
If [Form_ODDAPP FORM].[Risk No] <> "" Then
BMRange.Text = (CStr([Form_ODDAPP FORM].[Risk No]))
Else
BMRange.Text = (CStr(""))
End If
Thanks!
Access form. Everything has been working fine until today when I get this
error message: "Automation error, the server threw an exception." The
beginning of my code is pasted below. It seems to open the Word application,
but not the document. Is there a reference that I am missing?
Private Sub Contracts_Click()
On Error GoTo Err_Contracts_Click
Dim objWord As Word.Application
Dim JobHolder As String
Dim PhaseHolder As String
Dim BMRange As Range
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open ("Z:\ODDForms1.doc")
Set BMRange = objWord.ActiveDocument.Bookmarks("PIC").Range
If [Form_ODDAPP FORM].PIC <> "" Then
BMRange.Text = (CStr([Form_ODDAPP FORM].PIC))
Else
BMRange.Text = (CStr(""))
End If
Set BMRange = objWord.ActiveDocument.Bookmarks("Risk").Range
If [Form_ODDAPP FORM].[Risk No] <> "" Then
BMRange.Text = (CStr([Form_ODDAPP FORM].[Risk No]))
Else
BMRange.Text = (CStr(""))
End If
Thanks!