Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

asked on

Error when executing shell in access

Hello,
I have a odd problem, to which I've developed a work around.  However, I'm still curious as to why the error occurred in the first place.  I'm working on an application that is used to produce access reports and open word documents, some of which are merge documents. All the documents as well as the front-end reside on a network share.  Yes I know that each user should have their own copy of the front-end on their machine, however this is how the client wants it.

When I use the following code to open up a merged document, the word document opens up fine and the merge is executed.  However, when I try to open up a regular non-merge word document, I get an error message that the file is not found.  However, the message specifies a location on the "C:\Users\chtullu134\old.doc" has not been found.  I've stepped through the code and find that I am passing the correct code.  I'm not sure what is going on.
  Dim stAppName As String
  stAppName = "Winword.exe " & strDocPath
  Call Shell(stAppName, 1)

Open in new window


However, when using the following code to open a non-merge document, the document opens up fine.  The only problem is that while merged documents are opened up, the merge is not performed.  
'Code for non merge documente
    Dim intStrLength As Integer
    Dim strDocName As String
    Dim objWord As Object
    Set objWord = CreateObject("Word.Application")      
    Dim objPrinter As Printer
    Set objPrinter = Application.Printer
    With objWord
        .Activeprinter = objPrinter.DeviceName
        .Visible = True
        .Activate
        .Documents.Open (strDocPath)
    End With
    Set objWord = Nothing
    

Open in new window

Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Tried the first code and it works fine after specifying the path of the document.

    Dim stAppName As String
    stAppName = "D:\s.docx"
    stAppName = "Winword.exe " & stAppName
    Call Shell(stAppName, 1)

So how to reproduce the issue?
Avatar of Juan Velasquez

ASKER

Hello Hnasr,

I and all the other users are still having the same problem opening regular word documents using
Dim stAppName As String
    stAppName = "D:\s.docx"
    stAppName = "Winword.exe " & stAppName
    Call Shell(stAppName, 1)

Open in new window


I will be posting my solution when I get to the office.
ASKER CERTIFIED SOLUTION
Avatar of Juan Velasquez
Juan Velasquez
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I implemented the solution I described previously