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

Run batch file from Access VBA

Status
Not open for further replies.

rss0213

Programmer
Jul 12, 2007
58
US
I'm struggling to figure out what I'm doing wrong here...

I have two instances that I need to execute a batch file from my VBA code. The first one is working, but I can't get the second one to work. I keep getting the error "Method 'Run' of object 'IWshShell3' failed".

This is the code:

Set WSHs = CreateObject("WScript.Shell")
shResults = WSHs.Run("""C:\Documents and Settings\apprss\Desktop\Faxes\Returns\412072459-R.bat""", , True)

which I found on one of the posts on this site, but I've also tried:

Set WSHs = CreateObject("WScript.Shell")
WSHs.Run Chr(34) & varBatFile & Chr(34), , True

where "varBatFile" contains the full path and file name of the batch file to be executed. The batch file contains:

"C:\Documents and Settings\apprss\Desktop\Faxes\Returns\txt2pdf.exe" "C:\Documents and Settings\apprss\Desktop\Faxes\Returns\412072459-R.rpt" "C:\Documents and Settings\apprss\Desktop\Faxes\Returns\412072459-R.pdf" -pwa -pol90 -lpp56 -pfs9

This is a call to txt2pdf, which will convert a text document I'm creating (on the fly) to a PDF. When I execute this batch script manually, it works fine.

I'm thinking it's not the VBA code, and not something in my batch file, but when I use the two together, something gets hosed up.

All assistance is greatly appreciated! I've been beating my head against the wall for hours now!

Thanks!
Scott
 
Should I assume that since no one attempted to help me with this yesterday that this problem is "unresolvable"?

Thanks!
Scott
 



You might post in forum705, since this is MS Access.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I figured it out... The batch file that I'm creating on the fly wasn't getting closed prior to execution. I added one line: "objBatFile.Close", and now it works perfectly.


Thanks!
Scott
 
I just wanted to add (for informational purposes) that I'm instantiating a Wscript.shell object and utilizing the Run method to execute the batch file. This is in Access 2003 on a Win XP Pro machine.

Thanks!
Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top