Shell Command

J

Jasper Recto

I have a vb script(see below) in Access 2000 that is attached to a button.
The script is design to ask for a Part Number which is also the name of a
word .doc file. It then feeds that value into a path statement. Then a
shell command is supposed to open the specific word file. I can't seem to
get it to work.

Any ideas would be greatly appreciated!!

Private Sub Command3_Click()
Dim Title As String
Dim Default As String
Dim MyValue As Variant
Dim MyText As String
Dim MyPath As String
Dim Word
Dim DocPath

Title = "File Open"
Default = ""
MyText = "Enter Part Number in the format" & vbCr & _
"12345678"

MyPath = "C:\Vantage Documents\"

GetInput:
MyValue = InputBox(MyText, Title, Default)
If MyValue = "" Then
End 'quit subroutine
End If
On Error GoTo Oops 'just in case
DocPath = MyPath & "PN " & MyValue & _
"\" & MyValue
Word = Shell("C:\Program Files\Microsoft Office\Office\Winword.EXE &
DocPath", 1)
End 'End subroutine

Oops:

End Sub
 
S

Steven Burn

Try changing:

Shell("C:\Program Files\Microsoft Office\Office\Winword.EXE & DocPath", 1)

To

Shell("C:\Program Files\Microsoft Office\Office\Winword.EXE" & DocPath, 1)

Or

Shell("C:\Program Files\Microsoft Office\Office\Winword.EXE + DocPath", 1)



--
Regards

Steven Burn
Ur I.T. Mate Group CEO
www.it-mate.co.uk
 
P

Paul Overway

You need single quotes surrounding your paths, i.e.,

"'path to winword.exe'" & " 'path to document.doc'"
 
D

Douglas J. Steele

You've been given a couple of suggestions to make the Shell work. Another
option, though, is to use ShellExecute. (It has the advantage of not
requiring you to know where winword.exe exists)

Take a look at http://www.mvps.org/access/api/api0018.htm at "The Access
Web" for sample code.
 
V

Van T. Dinh

Steven

You need the space between Winword.exe and DocPath.

See my response to Jasper's earlier thread.
 
V

Van T. Dinh

I found single quotes didn't work when I tested (in WXP) my reply to
Jasper's earlier thread.

See the earlier thread for the one that worked (in WXP + AXP).
 
P

Paul Overway

Oops....you're right....needed double quotes, i.e.,

Shell chr(34) & "path to winword.exe" & Chr(34) & " " & Chr(34) & "path to
document.doc" & Chr(34)
 
P

Paul Overway

Reversing the quotes also works, i.e.,

Shell '"path to winword.exe"' & ' "path to document.doc"'
 
V

Van T. Dinh

Not too sure about the second one???

IIRC in my tests, Access VBA keeps thinking the first single-quote signals
that the rest of the line is a comment and I got error for it. It seems
weird but the remainder of the line keeps changing to green font (for
comments).
 
P

Paul Overway

You're right. Could've sworn I did it that way before. Should have quit
while I was ahead. LOL
 
V

Van T. Dinh

Yes, I agreed. I am sure I used single-quotes and double-quotes this way
somewhere else before. That's why I wrote "It seems weird ..."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top