473,854 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run a batch file from Microsoft Access

What's the trick to running a batch file from VBA? I'm trying to call
it using the Shell function but it's not working for me. If I
double-click the batch file or run it from the command line it works.

I've tried:

RetVal = Shell("cmd /c clean.bat", vbNormalFocus)
RetVal = Shell("clean.ba t", vbNormalFocus)
RetVal = Shell("<full path>clean.bat" , vbNormalFocus)
Call Shell...

Any help would be greatlyl appreciated!

Feb 3 '06 #1
26 34632
Shell "cmd /k c:\first.bat", vbNormalFocus

c:\first.bat is:
@echo off
rem this is the first batch file, first.bat
echo Calling second
call c:\second.bat
echo Returned from second
c:\second.bat is:
@echo off
rem this is second.bat
echo Running second batch file

Feb 4 '06 #2
Thanks mike & Lyle! I went with Lyle's suggestion. One other question.
If the path to the batch file contains spaces in the directory names,
how do I avoid the error: 'C:\Documents' is not recognized as an
internal or external command, operable program or batch file.

i.e. C:\Documents and Settings\csmith \Desktop\Extrac ts\clean.bat

It works if the path has no spaces e.g. c:\clean.bat, but not if the
path has spaces.

Feb 6 '06 #3
Shell "cmd /k ""C:\Docume nts and Settings\Lyle Fairfield\My
Documents\Acces s\first.bat""", vbNormalFocus

Feb 6 '06 #4
Thanks, Lyle. I tried that but I still get the same error:

Shell "cmd /k ""C:\Docume nts and
Settings\t83329 9\Desktop\Extra cts\clean.bat"" ", vbNormalFocus

Feb 6 '06 #5
It must be all one line.
Did you remove the line feed introduced by the news client?

Feb 6 '06 #6
Yes, it's on one line (I did remove the line feed). It's exactly like
yours except the path is C:\Documents and
Settings\t83329 9\Desktop\Extra cts\clean.bat. I'm looking at them
side-by-side. Any ideas? I still get 'C:\Documents' is not recognized
as an internal or external command, operable program or batch file.

Feb 6 '06 #7
No idea ... another way you could try is:

Dim s As String
s = "cmd /k " & Chr(34) & "C:\Documen ts and Settings\Lyle Fairfield\My
Documents\Acces s\first.bat" & Chr(34)
Shell s

Feb 6 '06 #8
Still have the same problem. Very weird.

Feb 6 '06 #9
Is there a way to accomplish the same thing using FileSystemObjec t?

Feb 6 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Jon Maz | last post by:
Hi All, To allow myself to make development changes directly on a remote server *without* having to compile on my local dev machine and then upload the dll's to remote, I have created a RunBatch.aspx on the remote which calls a batch file (myBuild.bat) on the same machine, and this batch file executes the necessary command-line compiler instructions to recompile (code below). So far (fingers crossed) it seems to be working. The only...
by: Mark C. | last post by:
I'm trying to call a batch file that I've built using the FileSystemObject and CreateObject("Wscript.Shell"), oShell.Run... in an asp script. Naturally, I can get the script to work from a command line but not from a browser. The page does not throw an error but the oShell.Run... portion of the script doesn't run. Any help would be appreciated. Thanks.
by: Rob | last post by:
I'm running a batch file using the Shell function. When I manually launch the batch file, the window remains open, since I use the 'pause' statement. But when I launch the batch file within Access, the Shell window becomes a blip on the screen and then is gone. Why does the Shell window not stay open on the screen? I want to visually verify that the batch file is functioning properly and then close the window myself. Am I missing a...
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup) 4) Once the copy is complete, the batch file opens the Access database again 5) EXIT should close out the cmd window but it does not execute that line
by: ScoobyDoo | last post by:
Anyone know how I can create and edit batch files from MS Access 2002?
by: Charles Neitzel | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
by: CliffKing | last post by:
I am trying to use Windows Task Scheduler to run a batch file for an already open MS Access database. Below is the syntax to the batch file: Batch file: DailySalesExport.bat REM This runs the macro that exports the reports to the J drive PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command" START /WAIT Msaccess.exe "D:\acesdata\SALES\Daily2005.mdb" /x "SnapShotExportDailySales" EXIT
by: Selva Chinnasamy | last post by:
Hi I am using batch commands against Ms-Access and getting an error Message "Characters found after end of SQL statement." String Here is my sql Dim str_screens As String = "Select * from Screens Order by ScreenName;Select * from Functions" How can I fix this problem. Any help is greatly appreciated. Selva
by: mvdkwong | last post by:
What's the trick to running a batch file from VBA? I'm trying to call it using the Shell function but it's not working for me. If I double-click the batch file or run it from the command line it works. I've tried: RetVal = Shell("cmd /c clean.bat", vbNormalFocus) RetVal = Shell("clean.bat", vbNormalFocus) RetVal = Shell("<full path>clean.bat", vbNormalFocus) Call Shell...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.