how to run an application

R

ravindar thati

i am using ms access 2003.
i want to run an application when i click a button.

the code is
Shell "c:\test.exe", vbNormalFocus


but this is static code.

i want to generate it dynamically.
i mean the path "c:\test.exe" changes each time.
so i stored that path in a string variable ST and tried executing
Shell " " & ST & " ",vbNormalFocus

i couldnt work out with it.
can any body suggest any changes to be done in that code. or else any
body please give a piece of code for my requirement
thanq
 
A

Andy Hull

Hi

Remove the spaces around the string variable...

Shell ST, vbNormalFocus

Regards

Andy Hull
 
B

Bob Hairgrove

i am using ms access 2003.
i want to run an application when i click a button.

the code is
Shell "c:\test.exe", vbNormalFocus


but this is static code.

i want to generate it dynamically.
i mean the path "c:\test.exe" changes each time.
so i stored that path in a string variable ST and tried executing
Shell " " & ST & " ",vbNormalFocus

Try this instead:

Shell ST, vbNormalFocus

In VBA, you only need quotes with string literals unless you are
constructing an SQL statement, for example, which needs embedded
quotes.
 
R

ravindar thati

Try this instead:

Shell ST, vbNormalFocus


thanq.

i am using the following code.
i want to search for a file "IFs.exe" in c drive.

Private Declare Function apiSearchTreeForFile Lib "ImageHlp.dll" Alias
_
"SearchTreeForFile" (ByVal lpRoot As String, ByVal lpInPath _
As String, ByVal lpOutPath As String) As Long

Function fSearchFile(ByVal strFilename As String, _
ByVal strSearchPath As String) As String
'Returns the first match found
Dim lpBuffer As String
Dim lngResult As Long
fSearchFile = ""
lpBuffer = String$(1024, 0)
lngResult = apiSearchTreeForFile(strSearchPath, strFilename,
lpBuffer)
If lngResult <> 0 Then
If InStr(lpBuffer, vbNullChar) > 0 Then
fSearchFile = Left$(lpBuffer, InStr(lpBuffer, vbNullChar)
- 1)
End If
End If
End Function



Private Sub Command0_Click()
Dim st As String
st = fSearchFile("IFs.exe", "C:\")
MsgBox (st)
Shell st, vbNormalFocus





the code MsgBox(st) prints the exact path where my file was located.
But when i executed the code
Shell st,vbNormalFocus,
it said that file not found in c:\documents and settings\RAVI
\MyDocuments\


infact my file location was c:\program Files\IFs\IFs.exe
why did it show like that?
what should i do?
 
D

Douglas J. Steele

ravindar thati said:
thanq.

Private Sub Command0_Click()
Dim st As String
st = fSearchFile("IFs.exe", "C:\")
MsgBox (st)
Shell st, vbNormalFocus


the code MsgBox(st) prints the exact path where my file was located.
But when i executed the code
Shell st,vbNormalFocus,
it said that file not found in c:\documents and settings\RAVI
\MyDocuments\

infact my file location was c:\program Files\IFs\IFs.exe
why did it show like that?
what should i do?

It's because there are spaces in the path.

Try:

Shell "" & st & "", vbNormalFocus
 
R

ravindar thati

Try this instead:
the same problem persist again.
though the path dynamicall passed through st, i.e c:\Program Files\IFs
\IFs.exe,
i wonder why it is searching in documents and settings, and displays
the msgbox, the file not found in documents and setting..............


thanq
 
R

ravindar thati

Try:

Shell "" & st & "", vbNormalFocus

--


the same problem persist again.
though the path dynamicall passed through st, i.e c:\Program Files
\IFs
\IFs.exe,
i wonder why it is searching in documents and settings, and displays
the msgbox, the file not found in documents and setting..............
 
A

Andy Hull

Hi

Try changing the 3rd from last line to...

st = chr(34) & fSearchFile("IFs.exe", "C:\") & chr(34)

Leave the last 2 lines as...

MsgBox (st)
Shell st, vbNormalFocus


Regards

Andy Hull
 

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