Variable in Shell Call under VBA

Hi, I have a shell command beneath a button on an access form which works well. My problem is that two directory locations specified within the current shell command can vary from user to user. Here is the VBA:

    'Shell """c:\program files\monarch\program\monarch"" ""C:\Temp\AvgBal.txt"" ""C:\Temp\AverageBalances\ModelFiles\AvgBal.xmod"" ""C:\Temp\AverageBalances\AvgBal.mdb"" /t", vbHide

The location C:\Temp can change, as can the C:\Temp\AverageBalances location. What I need is to create each location as a variable and then place the variable within the shell command. Can this be done, and how might it work?
jonlakeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pritamduttCommented:
You could use %TEMP% variable instead of the path.
0
jonlakeAuthor Commented:
I think I've nailed it with a little more thought! Here is what I ended up with:

    Dim Part01 As String, Part02 As String, Part03 As String, Part04 As String
   
    Part01 = "c:\program files\monarch\program\monarch"
    Part02 = "C:\Temp\AvgBal.txt"
    Part03 = "C:\Temp\AverageBalances\ModelFiles\AvgBal.xmod"
    Part04 = "C:\Temp\AverageBalances\AvgBal.mdb"
   
    Shell Part01 & " " & Part02 & " " & Part03 & " " & Part04 & " /t", vbHide

Now I can specify the variables within a table.
0
Steve KnightIT ConsultancyCommented:
If you want to do it as a variable (would be neater to read anyway) then do something like:

dim prog as string
dim thepath as string

prog="C:\program files\monarch\program\monarch"
thepath="c:\temp"

shell "" & prog & "" & " """ & thepath & "AvgBal.txt"" """ & ThePath & "AverageBalances\ModelFiles\AvgBal.xmod"" " & ThePath & """AverageBalances\AvgBal.mdb"" /t", vbHide

(I think...).

In summary "" gives you a " as you know.  Plus you terminate and end each string with a single " .  & to bring in a variable value, and & to continue with another string afterwards.

Is that the sort of thing you meant?

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Steve KnightIT ConsultancyCommented:
Crossed posts there.... yes that sort of thing.  Don't forget any " you need then around paths if they have (or may have) spaces in them.
0
jonlakeAuthor Commented:
Very helpful, thanks
0
Steve KnightIT ConsultancyCommented:
no problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.