Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Server threw an exception

Discussion in 'Information Technology' started by MSU Sptn2, Jul 28, 2006.

  1. MSU Sptn2

    MSU Sptn2
    Expand Collapse
    Guest

    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!
     
  2. Loading...


  3. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    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" <MSUSptn2@discussions.microsoft.com> wrote in message
    news:C1D2FD54-87DF-46B0-8390-F41B2BEF3169@microsoft.com...
    >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!
     
  4. MSU Sptn2

    MSU Sptn2
    Expand Collapse
    Guest

    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" wrote:

    > 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" <MSUSptn2@discussions.microsoft.com> wrote in message
    > news:C1D2FD54-87DF-46B0-8390-F41B2BEF3169@microsoft.com...
    > >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!

    >
    >
    >
     
  5. MSU Sptn2

    MSU Sptn2
    Expand Collapse
    Guest

    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" wrote:

    > 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" <MSUSptn2@discussions.microsoft.com> wrote in message
    > news:C1D2FD54-87DF-46B0-8390-F41B2BEF3169@microsoft.com...
    > >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!

    >
    >
    >
     
  6. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    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" <MSUSptn2@discussions.microsoft.com> wrote in message
    news:CFF8A97A-AF07-4D27-AF5F-E236E1626D91@microsoft.com...
    > 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" wrote:
    >
    >> 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" <MSUSptn2@discussions.microsoft.com> wrote in message
    >> news:C1D2FD54-87DF-46B0-8390-F41B2BEF3169@microsoft.com...
    >> >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!

    >>
    >>
    >>
     
  7. Tony Toews

    Tony Toews
    Expand Collapse
    Guest

    "Graham Mandeno" <Graham.Mandeno@nomail.please> wrote:

    >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
     
  8. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    Hi Tony

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

    But I don't quite see the point you were making.
    --
    Cheers,
    Graham M

    "Tony Toews" <ttoews@telusplanet.net> wrote in message
    news:jcdbb29b2t9j84kr8rpamo2t5asgv4fnqv@4ax.com...
    > "Graham Mandeno" <Graham.Mandeno@nomail.please> wrote:
    >
    >>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
     
  9. Tony Toews

    Tony Toews
    Expand Collapse
    Guest

    "Graham Mandeno" <Graham.Mandeno@nomail.please> wrote:

    >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
     
  10. Graham Mandeno

    Graham Mandeno
    Expand Collapse
    Guest

    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>

    --
    Cheers,
    Graham

    "Tony Toews" <ttoews@telusplanet.net> wrote in message
    news:40feb21oi0o6v0b9r62kagmenevij1nmlh@4ax.com...
    > "Graham Mandeno" <Graham.Mandeno@nomail.please> wrote:
    >
    >>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
     

Share This Page