• Automation Error (AccXP SP2)

    Author
    Topic
    #396288

    I have written an Access application which uses Automation and opens Word document from inside this application. All this works fine on Win2K/Acc2K where the application was developed, but the program does not work on Access XP, returning the message “Object is not connected to server”. On Win2K/AccXP, the program even bombs out. I traced the procedure and found that the program gets the error when it comes to the line “.Execute FindText:= ….” Does anybody have any idea about this problem?

    Thanks

    Viewing 3 reply threads
    Author
    Replies
    • #741575

      This is more or less conjecture, but you may need to check to see that you have the correct references (in particular to Word 10) in you code. There were also some changes in VBA and the support for legacy Word Basic in Word XP. Is this the first command where you attempt to do anything with the word document? If not, then I would suspect the problem is with the line you debugged to – otherwise it maybe that that Word is not happy being a server for some reason.

      • #741579

        Dear Wendell,

        Thanks for a quick reply. Yes, references are all correct. I refreshed them. Here is a portion of the program codes:

        Set wordObject = New Word.Application
        wordObject.Documents.Add TemplateFile

        wordObject.Selection.WholeStory
        Set rng = wordObject.Selection.Range

        With rng.Find
        .ClearFormatting
        .Execute FintText:=”abc”, Replacewith:=”xyz”, Replace:=wdReplaceAll
        End With

        wordObject.Visible = True
        Set wordObject = Nothing

        In the above codes,

        .Execute FintText:=”abc”, Replacewith:=”xyz”, Replace:=wdReplaceAll

        is where the program bombs out.

        As I was browsing around in MSDN, I found the following article, but wasn’t sure if this applies to my problem. In that article, they suggest I re-register Word Library by running Regtlib.exe, but I could not find the program on my and my colleague’s XP.

        http://support.microsoft.com/default.aspx?…kb;en-us;292744%5B/url%5D

        I would appreciate any further thoughts.

        (Edited by HansV to activate URL – see Help 19)

        • #741585

          Hasse’s suggestion of using late binding instead of early binding is spot on. I could reproduce the crash in a small test, but it works ok if you use the following:

          Dim wordObject As Object
          Dim rng As Object

          Set wordObject = CreateObject(“Word.Application”)

          • #741589

            Hasse and Hans,

            Thanks a lot. Late binding did work! (I didn’t know exactly what this meant.)

            Best

            • #741591

              Early binding means that you set a reference to the object library you’re going to use (in this case, the Microsoft Office n.0 Object Library), and use this object library in the declaration:

              Dim wordObject As Word.Application

              By doing this, you can inspect the properties and the methods of the object in design time. If you type wordObject followed by a period (dot), IntelliSense will kick in and display a list of available properties and methods. You will get a compile error if you try to use a non-existent property or method.

              Late binding means that you don’t specify the object type in the declaration:

              Dim wordObject As Object

              You won’t be able to use IntelliSense, and non-existing properties and methods won’t cause a compile error (but they will cause a runtime error.) You use CreateObject, which takes a string argument, to create the Word object; this is only resolved in runtime.

              In many cases, early binding is to be preferred, but sometimes you run into compatibility problems; this is apparently what happened to you. Then, late binding is better.

            • #741597

              Dear Hans,

              Thank you for your kind explanation of early-late binding. I bumped into this term often but ignored it (because I didn’t understand it). Now I feel I got wiser a bit.

              shlomos

            • #741598

              Dear Hans,

              Thank you for your kind explanation of early-late binding. I bumped into this term often but ignored it (because I didn’t understand it). Now I feel I got wiser a bit.

              shlomos

            • #741592

              Early binding means that you set a reference to the object library you’re going to use (in this case, the Microsoft Office n.0 Object Library), and use this object library in the declaration:

              Dim wordObject As Word.Application

              By doing this, you can inspect the properties and the methods of the object in design time. If you type wordObject followed by a period (dot), IntelliSense will kick in and display a list of available properties and methods. You will get a compile error if you try to use a non-existent property or method.

              Late binding means that you don’t specify the object type in the declaration:

              Dim wordObject As Object

              You won’t be able to use IntelliSense, and non-existing properties and methods won’t cause a compile error (but they will cause a runtime error.) You use CreateObject, which takes a string argument, to create the Word object; this is only resolved in runtime.

              In many cases, early binding is to be preferred, but sometimes you run into compatibility problems; this is apparently what happened to you. Then, late binding is better.

          • #741590

            Hasse and Hans,

            Thanks a lot. Late binding did work! (I didn’t know exactly what this meant.)

            Best

        • #741586

          Hasse’s suggestion of using late binding instead of early binding is spot on. I could reproduce the crash in a small test, but it works ok if you use the following:

          Dim wordObject As Object
          Dim rng As Object

          Set wordObject = CreateObject(“Word.Application”)

      • #741580

        Dear Wendell,

        Thanks for a quick reply. Yes, references are all correct. I refreshed them. Here is a portion of the program codes:

        Set wordObject = New Word.Application
        wordObject.Documents.Add TemplateFile

        wordObject.Selection.WholeStory
        Set rng = wordObject.Selection.Range

        With rng.Find
        .ClearFormatting
        .Execute FintText:=”abc”, Replacewith:=”xyz”, Replace:=wdReplaceAll
        End With

        wordObject.Visible = True
        Set wordObject = Nothing

        In the above codes,

        .Execute FintText:=”abc”, Replacewith:=”xyz”, Replace:=wdReplaceAll

        is where the program bombs out.

        As I was browsing around in MSDN, I found the following article, but wasn’t sure if this applies to my problem. In that article, they suggest I re-register Word Library by running Regtlib.exe, but I could not find the program on my and my colleague’s XP.

        http://support.microsoft.com/default.aspx?…kb;en-us;292744%5B/url%5D

        I would appreciate any further thoughts.

        (Edited by HansV to activate URL – see Help 19)

    • #741576

      This is more or less conjecture, but you may need to check to see that you have the correct references (in particular to Word 10) in you code. There were also some changes in VBA and the support for legacy Word Basic in Word XP. Is this the first command where you attempt to do anything with the word document? If not, then I would suspect the problem is with the line you debugged to – otherwise it maybe that that Word is not happy being a server for some reason.

    • #741581

      schlomos,
      I’ve never dealt with this problem and I’m no accustomed VBA-programmer, certainly not in XP but maybe this might be of some help:
      – late binding
      – reregister the Word type library on the system on which the problem occurs.
      I hope this is of some use…
      Hasse
      ps Source: http://www.experts-exchange.com/Applicatio…Q_20722227.html%5B/url%5D pointing to this Microsoft KB article: http://support.microsoft.com/default.aspx?…kb;en-us;292744%5B/url%5D

      URLs corrected by HansV

    • #741582

      schlomos,
      I’ve never dealt with this problem and I’m no accustomed VBA-programmer, certainly not in XP but maybe this might be of some help:
      – late binding
      – reregister the Word type library on the system on which the problem occurs.
      I hope this is of some use…
      Hasse
      ps Source: http://www.experts-exchange.com/Applicatio…Q_20722227.html%5B/url%5D pointing to this Microsoft KB article: http://support.microsoft.com/default.aspx?…kb;en-us;292744%5B/url%5D

      URLs corrected by HansV

    Viewing 3 reply threads
    Reply To: Automation Error (AccXP SP2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: