PDA

View Full Version : execute batch file



jan_sc
06-18-2008, 07:45 PM
hi,
i've got a simple batch file (abc.bat) that does file renaming from a.dat to b.dat.
the batch file content as below:


cd "C:\test"
rename "a_*.dat" b.dat
exit



there is no problem on the batch file as it works when manually execute the batch file.

the problem only happens when i'm using ms access (vba) to execute the batch file.
the code to execute the batch file as below:

sFile = "C:\test\abc.bat"
Call Shell(sFile, vbHide)

i even tried with this code Call Shell(Environ$("COMSPEC") & " /c " & sFile, vbHide) also doesn't work.


however, i've tested the vba using ms access xp, it works but not on ms access 2k. could this be the problem? anyone have experienced such before?

thanks!

Oorang
06-19-2008, 10:08 AM
As long as the path is good, the first syntax you posted will work just fine. Obviously the console window will not show if you use vbhide, but that shouldn't matter as long as the bat script doesn't have any prompts.

Although I wonder if you really need to be using a bat script. Unless you are doing something really esoteric you could probably do whatever the bat file is doing via vba. Can you post the bat script?

FrymanTCU
06-19-2008, 01:17 PM
Oorang, besides running batch files through VBA, can you create them as well? I'm almost embarassed:o: to share how we are currently creating this daily data file but if you can help automate the process even further it might be worth it.

Oorang
06-19-2008, 01:52 PM
Yup you can. VB has native functions for writing files, as well as the Microsoft Scripting Runtime (which most find easier to learn, but slower for large operations). But I'm trying to steer you into using vba to do what the batch files are doing for you, not into dynamically generating them:) Like I said, it's a pretty rare day when you can't port a BAT Script to VBA/VBScript.