Shell Puzzler - “Documents and Settings†folder issue?

B

Brad

I am trying to use Access VBA to initiate a small utility EXE file. The
Shell command is new to me. I ran into something that I don’t understand. I
have tried to boil it down as much as I can.

~~~~~~~~~~~

This works fine.
Shell "C:\TEST\Fired.exe"

~~~~~~~~~

The following command does not work. I receive a Run-time error “5†–
Invalid procedure call or argument.

Shell "C:\Documents and Settings\Fired.exe"



I have spent quite a bit of time on the internet to see if this is something
that others have run into. I have not yet found an explanation.

I am guessing that there is something “Special†about the “Documents and
Settings†folder that causes a conflict with the Shell command. I can move
the EXE file to a folder that does not have “Documents and Settings†in the
path, but I would like to better understand what is causing this problem.

Thanks,
Brad
 
T

Tom van Stiphout

On Wed, 2 Sep 2009 18:44:09 -0700, Brad

If you paste the command line:
C:\Documents and Settings\Fired.exe
in the Run box (Start > Run), you will get an error as well.
Reason: you need to wrap the entire thing in double-quotes, otherwise
the command line parser thinks you want to invoke "c:\documents" and
pass it a few arguments like "and" and "settings\fired.exe".

-Tom.
Microsoft Access MVP
 
B

Brad

Tom,

Thanks for the help. Your suggestion worked great!!!
The test statement looks like this…

Shell """C:\Documents and Settings\Fired 2.exe """

~~~~~

I am now trying to figure out all of the quotes needed to pass a parm to the
called EXE file (in a variable)

I have looked for an example, and tried several combinations, but no success.

Here is my latest attempt.

Shell """C:\Documents and Settings\Fired 2.exe """ & """ & my_parm & """

Perhaps you could point me in the right direction.

I really appreciate the assistance.

Thanks,
Brad
 
D

Dirk Goldgar

Brad said:
Tom,

Thanks for the help. Your suggestion worked great!!!
The test statement looks like this…

Shell """C:\Documents and Settings\Fired 2.exe """

~~~~~

I am now trying to figure out all of the quotes needed to pass a parm to
the
called EXE file (in a variable)

I have looked for an example, and tried several combinations, but no
success.

Here is my latest attempt.

Shell """C:\Documents and Settings\Fired 2.exe """ & """ & my_parm & """

Perhaps you could point me in the right direction.

I really appreciate the assistance.

I'll jump in because I was involved in an earlier version of this question.

Let's make the quote-handling easier by defining a constant to represent the
quote character:

'----- start of code -----
Const Q As String = """"

Dim strCommandLine As String


strCommandLine = _
Q & "C:\Documents and Settings\Fired 2.exe" & Q & _
" " & Q & my_parm & Q

Debug.Print strCommandLine ' To let you see what you get; remove later

Shell strCommandLine
'----- end of code -----

I believe that ought to work. Note that I added an unnecessary Debug.Print
to show you what the command line looks like in the Immediate Window.
Remove or comment out that line for production.
 
B

Brad

Dirk,

Good Good Good – Your suggestion worked great!

I love ya man!

I have spent several hours researching this problem on the internet and
experimenting. I had tried many combinations of double quotes,
double-double-quotes, double-double-double-quotes until I fell into
double-quote mania!

Seriously, I really appreciate the assistance. I work for a small firm
where I am the sole techie. This forum is a very valuable resource for those
of us who do not have other technical people onsite who we can go to with
questions.

I owe a big “THANK YOU†to you and the others who provide the help on this
forum.

Thanks again,

Brad
 
D

Dirk Goldgar

Brad said:
Good Good Good – Your suggestion worked great!

I'm glad to hear it.
I have spent several hours researching this problem on the internet and
experimenting. I had tried many combinations of double quotes,
double-double-quotes, double-double-double-quotes until I fell into
double-quote mania!

Quotes in quotes are a royal pain. That's why it's often easier to use a
constant to represent the quote character, or else -- and you'll see this a
lot -- use the Chr(34) function to return the quote character.
Seriously, I really appreciate the assistance. I work for a small firm
where I am the sole techie.

Been there, done that, so I understand. There's a lot to learn about
Access, but it's a terrific product, and fortunately there's a wonderful
community of people who are eager to help you learn.
 

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