Server threw an exception

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!
 
G

Graham Mandeno

This is a confusing message. It is referring to the automation server (the
Word process which is serving your Word.Application requests) not your
network server.

Do you know which line the error is occurring on? You could try commenting
out the "On Error" line, so that the code stops where the error occurs.
Then, in the debug window, you can examine different objects and structures
to see if they contain anything unexpected.

Are you certain that the file "Z:\ODDForms1.doc" actually exists and is
accessible?
 
M

MSU Sptn2

The code stops at .Documents.Open ("Z:\ODDForms1.doc"). The document does
exist and is accessible. In fact, it was working yesterday morning. The
only thing I changed since it worked was updating a missing reference to the
Microsoft Word Object Library.

Graham Mandeno said:
This is a confusing message. It is referring to the automation server (the
Word process which is serving your Word.Application requests) not your
network server.

Do you know which line the error is occurring on? You could try commenting
out the "On Error" line, so that the code stops where the error occurs.
Then, in the debug window, you can examine different objects and structures
to see if they contain anything unexpected.

Are you certain that the file "Z:\ODDForms1.doc" actually exists and is
accessible?
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MSU Sptn2 said:
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!
 
M

MSU Sptn2

Ok, I switched my reference from Microsoft Word 10.0 Object Library to
Microsoft Word 9.0 Object Library and the automation seemed to work okay. I
guess I will leave it alone!

Graham Mandeno said:
This is a confusing message. It is referring to the automation server (the
Word process which is serving your Word.Application requests) not your
network server.

Do you know which line the error is occurring on? You could try commenting
out the "On Error" line, so that the code stops where the error occurs.
Then, in the debug window, you can examine different objects and structures
to see if they contain anything unexpected.

Are you certain that the file "Z:\ODDForms1.doc" actually exists and is
accessible?
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MSU Sptn2 said:
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!
 
G

Graham Mandeno

Glad you got it fixed. My guess is that the Class ID for "Word.Application"
is creating a Word.Application.9 object (Word 2000) and there is some
compatibility issue between that and the Word 10.0 object library.

One way around these version compatibility issues is to remove the reference
after you have finished your development, and use "late binding".

Instead of:

Dim objWord As Word.Application

use

Dim objWord as Object
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MSU Sptn2 said:
Ok, I switched my reference from Microsoft Word 10.0 Object Library to
Microsoft Word 9.0 Object Library and the automation seemed to work okay.
I
guess I will leave it alone!

Graham Mandeno said:
This is a confusing message. It is referring to the automation server
(the
Word process which is serving your Word.Application requests) not your
network server.

Do you know which line the error is occurring on? You could try
commenting
out the "On Error" line, so that the code stops where the error occurs.
Then, in the debug window, you can examine different objects and
structures
to see if they contain anything unexpected.

Are you certain that the file "Z:\ODDForms1.doc" actually exists and is
accessible?
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MSU Sptn2 said:
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!
 
T

Tony Toews

Graham Mandeno said:
One way around these version compatibility issues is to remove the reference
after you have finished your development, and use "late binding".

Graham

Pardon me for jumping in: Standard blurb follows.

Late binding means you can safely remove the reference and only have
an error when the app executes lines of code in question. Rather than
erroring out while starting up the app and not allowing the users in
the app at all. Or when hitting a mid, left or trim function call.

You'll want to install the reference if you are programming or
debugging and want to use the object intellisense while in the VBA
editor. Then,. once your app is running smoothly, remove the
reference and setup the late binding statements.

Sample code:
' Declare an object variable to hold the object
' reference. Dim as Object causes late binding.
Dim objWordDoc As Object
Set objWordDoc = CreateObject(" Word.Document")

For more information including additional text and some detailed links
see the "Late Binding in Microsoft Access" page at
http://www.granite.ab.ca/access/latebinding.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
G

Graham Mandeno

Hi Tony

Jump in, by all means - you are very welcome :)

But I don't quite see the point you were making.
 
T

Tony Toews

Graham Mandeno said:
Jump in, by all means - you are very welcome :)

But I don't quite see the point you were making.

I was just expanding on your comment about late binding with more
information.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
G

Graham Mandeno

Ah... right - thanks for that. I thought you were offering a subtle
correction, but I couldn't see what it was you were correcting <smile>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top