Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access to Word (Office 2000 Premium)

    I have written some code for a module in Access 2000 that carries out a TransferText Action. It opens Word (2000), goes to the specific merge document, merges to a new document then closes the original merge document.
    This is the appropriate section of the code:

    DoCmd.TransferText acExportMerge, , strQuery, strData
    DoCmd.Close acForm, "PrintItems"

    Call Shell("""C:Program FilesMicrosoft OfficeOfficeWinword.exe"" ""C:My DocumentsWinwordBusiness" & strFolderDoc & ".doc""", vbMaximizedFocus)
    With ActiveDocument.MailMerge
    .Destination = wdSendToNewDocument
    .Execute

    End With
    Windows(strActualDoc).Close (WdSaveOptions.wdDoNotSaveChanges)

    It works well.
    But the problem is it only works well once - if I use it again for another letter I get this error statement and it only gets as far as the original merge document. (It opens it with the merge info but does not merge to a new doc)

    Error No: 462 - Error Description: the remote server machine does not exist or is unavailable.

    I am not networked.

    I have no idea why it does this - is there a connection still open to Word that shouldn't be? Can anyone help?
    Thanks
    Peter Herworth

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access to Word (Office 2000 Premium)

    Your code closes the document but it doesn't exit the Word application, so I suspect that is why you're getting the error, particularly since Shell executes asynchronously. If you assign the Shell result to a variable instead of just calling it, you'll get the the application's task ID which can be used later with the AppActivate statement to activate Word. Then you should be able to use an Application.Quit to close it.

    You might have better luck using automation instead of the Shell command, since Access can do this by directly manipulating Word. There's a link in this post that will take you to a download on Office automation which might help.
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access to Word (Office 2000 Premium)

    Thanks Charlotte - I suspected something like that.. The trouble is because it is asynchronous I can't close it from within the code until I've checked and printed it and I need to check it first. Is there a way round that or am I going to have to start learning something new with these samples I've downloaded from the site you mention.
    Thanks again. I'll try it
    Peter H

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access to Word (Office 2000 Premium)

    The only way I can think of is to train yourself or you users to close Word from the Windows interface. Otherwise, only using automation is going to give you any significant control of events.
    Charlotte

Posting Permissions

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