Results 1 to 12 of 12
  1. #1
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Controlling Word from Access (2003)

    I have an Access application that uses a command button to open a certain file in Word. The code that opens the file is:

    Shell ("c:/Program Files/Microsoft Office/OFFICE11/WINWORD.EXE c:/USSRN/Envelope.doc"), vbNormalFocus

    What I REALLY want to do is, instead of opening the file, to have Word present itself with its Open dialog box visible, showing all the documents in the c:/USSRN directory. That way, the user can select which one he wants to open, rather than having to settle for Envelope.doc.

    I'd greatly prefer to do this from the VBA in the Access application, rather than invoking some sort of Word macro.

    Any suggestions?
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Controlling Word from Access (2003)

    This is called Automation. Access moderator <!profile=WendellB>WendellB<!/profile> has a tutorial on his website, with useful links: Automation 101.
    See <post#=156810>post 156810</post#> for an example of how to display the File | Open dialog.

    Note: for Word 2003, you need to set a reference tro the Microsoft Word 11.0 Object Library.

  3. #3
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Re: Controlling Word from Access (2003)

    Thanks! This looks like exactly what I need.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  4. #4
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Re: Controlling Word from Access (2003)

    Oops!

    I don't know what you mean by "set a reference to the Microsoft Word 11.0 Object Library."
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Controlling Word from Access (2003)

    Activate the Visual Basic Editor (if you're not already there)
    Select Tools | References...
    You'll see a list of object libraries. The ones whose check boxes are ticked are the ones available to your code now, such as Visual Basic for Applications and Microsoft Access 11.0 Object Library (there will be a few others, most probably).
    Scroll down the list until you see Microsoft Word 11.0 Object Library, and tick its check box, then click OK.
    You can now use Word VBA in your Access application.

  6. #6
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Re: Controlling Word from Access (2003)

    Got it! I wasn't in the VB editor when I was trying to find it.

    This stuff is lots of fun, but there's sure a lot to know. The whole VBA thing is HUGE. (I got started in the Commodore 64 days, when it was possible to know and understand every single BASIC keyword, and I knew and understood them.)
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Controlling Word from Access (2003)

    When I write Word VBA in Access, I usually start out in Word itself, perhaps recording a macro, or writing snippets of code and trying them out directly. This is easier than starting from scratch in Access. Once I know what the Word code should look like, I transfer it to Access, taking care to prefix items with the appropriate object, e.g. Documents becomes appWord.Documents, if appWord is the Word.Application object used in Access.

  8. #8
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Re: Controlling Word from Access (2003)

    Good advice. I'll try it.

    I'm wondering if my Access application won't work on computers that don't have the Word Object Library activated. Any ideas?
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Controlling Word from Access (2003)

    The user needs to have Word installed. The Word Object Library comes with it. If the user doesn't have Word, your code obviously won't work at all.

    BTW, will all your users have Office 2003, or will some of them have Office 2000 or Office XP?

  10. #10
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Re: Controlling Word from Access (2003)

    Right now I am the only user. But my application is getting so good that other members of our group are interested in using it. They could have any version of Word, or no version at all, but I imagine if they have Access, they have Word.

    I'm using Access 2003, and I'm not sure whether other users would need to have that version as well.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Controlling Word from Access (2003)

    If you ever need to make your application available to users with Word 2000 or 2002, you'll have to modify some things, but that can be done at the end. For development, just continue the way you do now. You can ask when you come to it, or search for late binding.

  12. #12
    5 Star Lounger Lou Sander's Avatar
    Join Date
    Jun 2002
    Location
    Pittsburgh, PA
    Posts
    855
    Thanks
    140
    Thanked 10 Times in 9 Posts

    Re: Controlling Word from Access (2003)

    I will keep that in mind, against the day that others also use my application.

    In the meantime, I have just implemented your suggestions and those of the references you gave, and Word is doing PRECISELY what I want it to do, all from my Access application!

    Thank you very much.
    Lou Sander
    Pittsburgh, Pennsylvania
    USA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •