Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem running program from cmd button

Status
Not open for further replies.

upplepop

IS-IT--Management
Jun 1, 2002
173
US
I have a command button to run a program by using this code:

Private Sub cmdASI_Click()
On Error GoTo Err_cmdASI_Click
Dim stAppName As String
stAppName = "C:\AccuCare\Ac550.exe"
Call Shell(stAppName, 1)
Exit_cmdASI_Click:
Exit Sub
Err_cmdASI_Click:
MsgBox Err.Description
Resume Exit_cmdASI_Click
End Sub


The problem is, the program needs to "Start In" its folder so it can access other files. Is there any code to tell the Command button to start the program in the "C:\AccuCare" directory??
 
Hi,

Here's a possiblity, it's what I have done in Windows 2000 or NT. Not sure if this will work in 95 or 98.
I'm sure there are some other ways to do the same thing.



Call CMD.exe from the shell function instead of the command itself. Use the && to string together commands.


stAppName = "cmd /k c: && cd \ && cd winnt && dir /w"
' will call call cmd.exe keeping the dos window open
' change to the C drive,
' issue Go to the root dir
' change to the winnt directory
' do a DIR on that directory.

See CMD /? for more info.



Mark
 
Or, for a solution that works on all operating systems, see faq705-2299.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top