• Opening Word from Access (2003)

    Author
    Topic
    #410170

    I have looked through the old posts and found a thread that has helped me get the code I think I need to open a Word document from Access. I have modified it slightly but I need to run this code from a command button, I used this code which I thought would work

    Private Sub cmdNotes_Click()
    Call OpenWordDoc(“U:Global InformationUser ManualsExpenseTracking.doc”)
    End Sub

    Public Sub OpenWordDoc(strFilePath As String)
    Dim appWord As Word.Application
    Dim doc As Word.Document
    strFilePath = “U:Global InformationUser ManualsExpenseTracking.doc”
    Set appWord = New Word.Application
    Set doc = appWord.Documents.Open(strFilePath)
    appWord.Visible = True
    appWord.Activate
    Set appWord = Nothing
    Set doc = Nothing
    End Sub

    Now I’m getting a new error:

    Compile Error:
    User-defined type not defined.

    Where am I going wrong?

    Viewing 1 reply thread
    Author
    Replies
    • #879499

      Which line or you getting the error on? Do you have a reference set to the Word object library?

      • #879511

        Oops sorry, its this line:

        Set appWord = New Word.Application

        I have set a reference to the Word object library.

        I also getting this message now (attachment)

        rgds
        Hayden

        • #880290

          Try replacing

          Set appWord = New Word.Application

          with

          Set appWord = CreateObject(“Word.Application”)

          • #880398

            Thanks Hans

            I have replaced the code as you suggest but I’m still getting an error.

            Unfortunately I can’t get my screen dump smaller than 100k otherwise I would have attached it.

            But just to confirm:
            I have set a reference to Microsoft Word 11.0 Object Library
            The error I’m getting is: Run time error ‘-2147024770 (8007007e)’: Automation error The specified module could not be found. For this line in the code: Set appWord = CreateObject(“Word.Application”)
            What I’m trying to do, is enable the user to open a word document which contains a user manual for the database they are using. If there is a better way than this I would be interested to learn about it.

            Many thanks again
            Hayden

            • #880406

              If you want, you can send the db to me (see my profile). I’ll see if I can find something.

            • #880408

              Francois, that’s very kind of you, it’s on it’s way.

              Regards
              Hayden

            • #880413

              Hayden,

              I tested your db on my pc. I had no problem to run it. Word document, after changing the path and file name to an existing doc on my pc, was opening as expected.
              Doing a google search on the error message you receive, I found a lot of stuff about error 2147024770, all referring to missing dll files. But nowhere there is an explicit name of the dll file.

              Can you try to do a detect and repair of office ?
              In the Help menu select Detect and Repair and see what’s the result.
              You’ll need the office cd’s.

            • #880427

              Thanks Francois

              I’ll give this a try and let you know what happens.

              Regards
              Hayden

            • #880428

              Thanks Francois

              I’ll give this a try and let you know what happens.

              Regards
              Hayden

            • #880437

              Right, I have done what you suggested and I’m still getting the same error.

              I ticked the “Restore my shortcuts while repairing” box and a Pop up box saying “Setup completed successfully” appeared. I rebooted the machine and tried the button, which didn’t work.

              There is another option on the repair menu, which wasn’t ticked when I open the menu, which says “Discard my customized settings and restore default settings”. Is it worthwhile ticking this and running the repair again?

              Regards
              Hayden

            • #880445

              I don’t think custom settings have anything to do with your problem. It seems that VB cannot find the Word object library. Do you have multiple versions of Word on your PC? (MS Office, MS Works)

            • #880447

              Hi Hans

              No I only have MS Office Professional 2003 installed.

              Regards
              Hayden

            • #880451

              Your code is OK (and it works on Francois’ PC). You might test this further by copying the database and Word doc to another PC. Since a Detect and Repair didn’t work on the problem PC, you may have to uninstall and reinstall Office 2003.

            • #880455

              OK Hans,

              Thanks for the tip, will let you know what happens.

              Regards
              Hayden

            • #880461

              Just as a random thought…you haven’t got any other ‘odd’ references set that may be MISSING (maybe not even linked to MS Word or Office)? You can check this by going to TOOLS –> REFERENCES and making sure none of the checked ‘available references’ have the words MISSING in front of them?

            • #880467

              I have checked the references and none of them have the word MISSING in front of them

              I have attached a screen print of the references that I have set.

              Rgds
              Hayden

            • #880468

              I have checked the references and none of them have the word MISSING in front of them

              I have attached a screen print of the references that I have set.

              Rgds
              Hayden

            • #880462

              Just as a random thought…you haven’t got any other ‘odd’ references set that may be MISSING (maybe not even linked to MS Word or Office)? You can check this by going to TOOLS –> REFERENCES and making sure none of the checked ‘available references’ have the words MISSING in front of them?

            • #880456

              OK Hans,

              Thanks for the tip, will let you know what happens.

              Regards
              Hayden

            • #880452

              Your code is OK (and it works on Francois’ PC). You might test this further by copying the database and Word doc to another PC. Since a Detect and Repair didn’t work on the problem PC, you may have to uninstall and reinstall Office 2003.

            • #880457

              Before uninstalling, maybe you can try to re-register the Word Object Library.
              Have a look at MSKB article 292744 to find out how to do this.

            • #880469

              Francois, I’ll go through your attachment.

              I have tried the database on another PC and I’m happy to report that the button which opens the Word file works.

              I’m quite pleased that my code actually works, I just have to get my PC working now.

              Rgds
              Hayden

            • #880470

              Francois, I’ll go through your attachment.

              I have tried the database on another PC and I’m happy to report that the button which opens the Word file works.

              I’m quite pleased that my code actually works, I just have to get my PC working now.

              Rgds
              Hayden

            • #880519

              Hi Francois,

              I’m trying to re-register the Word library, but I don’t understand a few of the things I need to do, should I persist with it or just re-install Office again?

              Rgds
              Hayden

            • #880687

              You can reinstall. I hope this will solve the problem

            • #880688

              You can reinstall. I hope this will solve the problem

            • #880520

              Hi Francois,

              I’m trying to re-register the Word library, but I don’t understand a few of the things I need to do, should I persist with it or just re-install Office again?

              Rgds
              Hayden

            • #880458

              Before uninstalling, maybe you can try to re-register the Word Object Library.
              Have a look at MSKB article 292744 to find out how to do this.

            • #880448

              Hi Hans

              No I only have MS Office Professional 2003 installed.

              Regards
              Hayden

            • #880446

              I don’t think custom settings have anything to do with your problem. It seems that VB cannot find the Word object library. Do you have multiple versions of Word on your PC? (MS Office, MS Works)

            • #880438

              Right, I have done what you suggested and I’m still getting the same error.

              I ticked the “Restore my shortcuts while repairing” box and a Pop up box saying “Setup completed successfully” appeared. I rebooted the machine and tried the button, which didn’t work.

              There is another option on the repair menu, which wasn’t ticked when I open the menu, which says “Discard my customized settings and restore default settings”. Is it worthwhile ticking this and running the repair again?

              Regards
              Hayden

            • #880414

              Hayden,

              I tested your db on my pc. I had no problem to run it. Word document, after changing the path and file name to an existing doc on my pc, was opening as expected.
              Doing a google search on the error message you receive, I found a lot of stuff about error 2147024770, all referring to missing dll files. But nowhere there is an explicit name of the dll file.

              Can you try to do a detect and repair of office ?
              In the Help menu select Detect and Repair and see what’s the result.
              You’ll need the office cd’s.

            • #880409

              Francois, that’s very kind of you, it’s on it’s way.

              Regards
              Hayden

            • #880407

              If you want, you can send the db to me (see my profile). I’ll see if I can find something.

          • #880399

            Thanks Hans

            I have replaced the code as you suggest but I’m still getting an error.

            Unfortunately I can’t get my screen dump smaller than 100k otherwise I would have attached it.

            But just to confirm:
            I have set a reference to Microsoft Word 11.0 Object Library
            The error I’m getting is: Run time error ‘-2147024770 (8007007e)’: Automation error The specified module could not be found. For this line in the code: Set appWord = CreateObject(“Word.Application”)
            What I’m trying to do, is enable the user to open a word document which contains a user manual for the database they are using. If there is a better way than this I would be interested to learn about it.

            Many thanks again
            Hayden

        • #880291

          Try replacing

          Set appWord = New Word.Application

          with

          Set appWord = CreateObject(“Word.Application”)

      • #879512

        Oops sorry, its this line:

        Set appWord = New Word.Application

        I have set a reference to the Word object library.

        I also getting this message now (attachment)

        rgds
        Hayden

    • #879500

      Which line or you getting the error on? Do you have a reference set to the Word object library?

    Viewing 1 reply thread
    Reply To: Opening Word from Access (2003)

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

    Your information: