• Access to Word (Office 2000 Premium)

    Author
    Topic
    #358536

    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

    Viewing 0 reply threads
    Author
    Replies
    • #535224

      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.

      • #535229

        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

        • #535239

          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.

    Viewing 0 reply threads
    Reply To: Access to Word (Office 2000 Premium)

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

    Your information: