Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

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

0
chtullu135
Asked:
chtullu135
  • 3
1 Solution
 
hnasrCommented:
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?
0
 
chtullu135Author Commented:
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.
0
 
chtullu135Author Commented:
I created an if statement to call either the shell command for merge documents or the following vba code if it is a non merge document
'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

0
 
chtullu135Author Commented:
I implemented the solution I described previously
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now