Can't run Batch file

A

Alex

I am using the following code to create a batch file and then run it from
Access. The batch file is sucessfully created and it then proceeds to run
but the output fie of the batch is never created. The batch will only work
when I run it with my mouse.


Public Sub CreateAfile()
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("C:\alex\Nelson\test\batch.bat", True)
A.WriteLine ("copy C:\alex\Nelson\test\$test $test.TXT")
A.Close
Call Shell("C:\alex\Nelson\test\batch.bat", 1)
End Sub
 
B

BeWyched

Hi Alex

Your coding is fine except that you should add the full path to the
destination folder. I've no idea why this is needed (as you say, running the
batch file as its written outside of Access works) but it is - a quirk of
Access !

So, rewrite your line:
A.WriteLine ("copy C:\alex\Nelson\test\$test $test.TXT")
as
A.WriteLine ("copy C:\alex\Nelson\test\$test C:\path to folder\$test.TXT")

Cheers.

BW
 
D

Douglas J. Steele

Why not just use the built-in VBA FileCopy command?

No need for FSO and batch files!
 
B

BeWyched

Judging by the original coding, Alex must be looking to combine several text
files into one (otherwise his coding is irrational).

'FileCopy' will not do this and, so far as I am aware, DOS commands are the
simplest way of doing this. So long as all the files in his $test folder are
text files they will all be combined into the $test.txt file.

BW
 

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