Shell Command

M

Mike Charney

I am trying to shell out to run a VB script file. I do not need to track the
progress of the shell. It can fire off and then the VBA code can continue.

The code I have is:

hTask = Shell("c:\Cdosmtp.vbs", 1)

I have tried to dim hTask as an integer and Long, as well as no designation
but I am receiving a Run-time Error 5 on that line.

Is this not the correct way to shell from an Access VBA module?

I have never used the shell command in Access VBA before, how does it work?

Mike
m charney at dunlap hospital dot org
 
D

Douglas J Steele

I don't believe you can simply shell to a vbs file: you need to include
either cscript.exe (to run in batch) or wscript.exe (to run interactively):

hTask = Shell("cscript.exe c:\Cdosmtp.vbs", 1)

Another alternative to the Shell command is the ShellExecute API. It will
automatically run any file using the application associated with the file
extension in the registry. See http://www.mvps.org/access/api/api0018.htm at
"The Access Web" for a complete example.
 
L

Larry Daugherty

There ARE other resources than posting into the newsgroups!

From the code window it took me less than 5 seconds to bring up Access
HELP and look at the example they give of the Shell command.

HTH
 
M

Mike Charney

I looked up the shell command the line of code I put in the post was like
the help file mentioned except that it was running an exe and I was running
a VB script file.

Thanks to Doug. I needed to add the cscript.exe to the line. It works great
now!!

Thanks to all...
Mike
 

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