473,657 Members | 2,896 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 34552
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

2
1912
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...
14
3546
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.
1
15184
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...
4
47492
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
4
3346
by: ScoobyDoo | last post by:
Anyone know how I can create and edit batch files from MS Access 2002?
6
11215
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...
4
26811
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
12
5126
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
1
1695
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...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
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...
1
8499
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,...
0
7314
agi2029
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...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.