The dos shell and Start Run cmd use the path environment variable if the
executable's path isn't given. VBA's Shell function uses the current
directory if the executable's path isn't given. Sample.bat isn't in the
current directory. Type the full path to sample.bat to solve the problem.
Quote:
>I have come across a strange issue whilst trying to use a shell
>command call from Access and have spent some time trying to figure
>this out but can't find the cause as yet.
>
>The issue is: I need to execute a command call from within Access to
>execute a batch file (sample.bat). To do this, we use the Shell
>function, something like:
>
>Shell "cmd /c sample.bat"
>
>sample.bat is located in C:\WINDOWS\system32 and this directory is set
>in the PATH variable.
>
>The issue is that when I attempt to execute the Shell call, I get the
>following message:
>'sample.bat' is not recognized as an internal or external command,
>operable program or batch file.
>
>My environment is Windows XP SP2 and Access 2003.
>
>So I jump to my Start Run cmd to invoke command line, then execute
>sample.bat and it works!
>
>To further debug this issue, this is what I've done and found so far:
>a) On Access, perform a Shell call that looks like: Shell "cmd /k".
>This opens up a Command window.
>b) I also open a Command window by going to Start Run cmd.
>
>PATH
>* On both (a) and (b) I verify that 'C:\WINDOWS\system32' is
>definitely in the PATH, so sample.bat can be executed without
>prefixing its location (yes, I anyways tried to prefix the location
>but didn't help)
>DIR
>* On (b), I go to the directory C:\WINDOWS\system32 and then execute a
>'dir sample.bat' and find the file
>* On (a), I go to the directory C:\WINDOWS\system32 and then execute a
>'dir sample.bat' and can't find the file!!!
>CHANGE THE LOCATION OF sample.bat to C:\
>* On (b), I set the PATH to C:\ and execute sample.bat and it works
>* On (a), I set the PATH to C:\ and execute sample.bat and it
>works!!!! Of course, I can now do a DIR and find the file
>
>Even though I found a workaround to my issue, I am baffled as to why
>the Command interpreter behaves differently when called from within
>Access compared to when it's called from the Start Run option.
>
>The workaround is less attractive if, for example, you need to run
>some other commands (like CSVDE) that should actually be in the
>directory C:\WINDOWS\system32 and it doesn't work (which is also
>happening to me).
>
>I log on as a local admin, I even opened up the permissions on the
>root C:\WINDOWS to Everyone and have it propagated to all the
>subfolders but I still get that on (a); I can't see sample.bat or
>CSVDE.exe and, therefore, I can't execute the file.
>
>Any clues would be highly appreciated!