Passing a Variable to a called program in a Shell Command

B

Brad

This should be simple. I am trying to initiate a little program called
“Fired.exe†from an Access VBA routine.

I can initiate the program with no passed parameter just fine.

I can initiate the program and pass it a parameter that is “hard coded†in
the Shell statement.

Now I am simply trying to initiate the program and pass it a parameter that
is contained in a variable. I am pulling my hair out as I have done quite a
bit of digging and experimenting with no success.

Here is the gist of my code…

‘~~~~~~~~~~~~~~~~~~~~
Dim my_parm As String
my_parm = "NO"

' This works (no parm is passed)
Shell "C:\Fired.exe"

' This works (Hard-coded "YES" is passed to Called Program)
Shell "C:\Fired.exe YES"

' Now I want to pass a parm that is a variable – I cannot figure out how to
make this work.
Shell ("C:\Fired.exe my_parm") ???
Shell ("C:\Fired.exe & my_parm") ???

‘~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks for your help with this,
Brad
 
D

Dirk Goldgar

Brad said:
This should be simple. I am trying to initiate a little program called
“Fired.exe†from an Access VBA routine.

I can initiate the program with no passed parameter just fine.

I can initiate the program and pass it a parameter that is “hard coded†in
the Shell statement.

Now I am simply trying to initiate the program and pass it a parameter
that
is contained in a variable. I am pulling my hair out as I have done quite
a
bit of digging and experimenting with no success.

Here is the gist of my code…

‘~~~~~~~~~~~~~~~~~~~~
Dim my_parm As String
my_parm = "NO"

' This works (no parm is passed)
Shell "C:\Fired.exe"

' This works (Hard-coded "YES" is passed to Called Program)
Shell "C:\Fired.exe YES"

' Now I want to pass a parm that is a variable – I cannot figure out how
to
make this work.
Shell ("C:\Fired.exe my_parm") ???
Shell ("C:\Fired.exe & my_parm") ???

‘~~~~~~~~~~~~~~~~~~~~~~~~~


Try this:

Shell "C:\Fired.exe " & my_parm

If the parameter value contains space, you'll need to force it to be wrapped
in quotes, like this:

Shell "C:\Fired.exe """ & my_parm & """"

Note that the quotes are doubled within the quoted literals; each internal
doubled quote will be interpreted as only one quote.
 
B

Brad

Dirk,

Good Good Good!

Not sure if you are a beer drinker or not, but if you are, I owe you a tall
one!

It was the space after the .exe that I was missing

C:\Fired.exe" & my_parm <--- what I had tried, no success

C:\Fired.exe " & my_parm <--- what you suggested – SUCCESS

Thanks again. You have restored my faith in the goodness of humanity!

Brad
 

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