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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to run command line commands from VBA - How

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
I have a set of Command line commands I would like to run from vba in MS Access.
-------------------------------------
echo off

cd "c:\ARMS"

dir/b>tempfile.txt

exit
------------------------------------
I have a batch file that runs these now but I would like to cut out the middle man and run it directly from my Access DB.

How can I code this please.

Thanks,
 
You could run your bat file using Shell().

Shell("MyBatch.bat")

Or to do everything from inside VBA, as a starting point.

Code:
Public Sub ListDir(oPath As String)
Dim oFileName As String

oFileName = Dir(oPath, vbNormal)

Do While oFileName <> ""
Debug.Print oFileName
'Get the next file name
oFileName = Dir
Loop
End Sub

You'll need to replace the debug.print with Write() and support that with a bit to set up a file.
And to match the "/b" switch you'll need to chop of the extensions.
 
Running the bat file using Shell sounds like a plan...however..can you explain the VB so I can learn how and why it works. Maybe put the parts where I would insert my information in {}? would I punt the file name (path c:\ARMS) in place of something. And what does the Write() do. Also what part of the code stores the "tempfile.txt"? I assume the looping is compiling all the file names inside the c:\ARMS folder to list them in the tempfile.txt. I gave you all the commands I want to call between the .....lines.

In other words...a little more detail about what your code is doing. This way I will learn what the code means.

Thanks for your response.
 
I gave you some code that works and some pointers on where to take it.

How about you make a little effort now?
 
One of the best ways (in my opinion) to learn/see what's going on and what happens with the code is to set some break points in code and step thru it (F9). If you hover above the variables with your mouse - you will see the values in them.

Give it a try... :)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top