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

Run External Batch File - Strange Results 1

Status
Not open for further replies.

xweyer

MIS
Sep 7, 2000
140
US
I'm trying to create a button on a form that will pass control to an external batch file and then close Access. The batch file, which creates a backup of the database, runs fine outside of Access but behaves strangely when run from the button.

I'm not all that surprised that I've run into a problem doing this but the particular probem that results has me mystified.

When the button is clicked Access closes and a Dos Window appears immediately displaying the "Backup Complete" message. (Way too quickly for the file to have actually copied). Clicking any key then restarts the database.

The code for the button is
Call Shell("K:\Access\Stock\DbBkUp.bat", 1)

Further testing strongly indicates that lines in the batch file which involve the creation or renaming of files are ignored but all other lines are executed appropriately.

Does that make any sense?

Although I can work around the problem pretty simply by having the user run the batch file himself after Access closes (this is the way it works in the current application that I'm replicating in Access) I'd much prefer to understand what is happening.

Here's the batch file.

DbBkUp.bat
@echo on
@rem This batch file will make a new backup of Stock.mdb (up to a total of five backup copies).
@echo off

rem Wait until db closes

@echo on
@echo Waiting for Stock.mdb to close... Press "<Ctrl><Break>" to terminate backup
@echo off

:wait4cls
If exist stock.ldb goto wait4cls else goto prep

:prep
rem Delete oldest backup (if it exists)
cls
if exist Stock5.mdb Del Stock5.mdb else goto re-rank
goto re-rank

:re-rank
rem Rename existing backups
if exist Stock4.mdb rename Stock4.mdb Stock5.mdb
if exist Stock3.mdb rename Stock3.mdb Stock4.mdb
if exist Stock2.mdb rename Stock2.mdb Stock3.mdb
if exist Stock1.mdb rename Stock1.mdb Stock2.mdb

:bkup
rem Copy Stock.mdb as Stock1.mdb
cls
@echo on
@echo Creating Backup. This may take several minutes. Please be patient.
@echo off
If exist Stock.mdb copy stock.mdb Stock1.mdb

:done
cls
@echo on
@Echo Backup Complete. Click on this screen if it is not already selected and
@pause
@echo off

rem restart Access open db

stock.mdb
goto end

:end
 
Could the batch be running in the wrong directory. I mean did you try adding CD's to ensure the right folder?? I wouldn't think so because the db starts up again, but it would explain the quick pass through the rest of the batch.
 
You nailed it stix4t2.

The fact that the database opened drew me away from that line of thinking completely. I was expecting something exotic.

Once I specified the path everything worked fine.

Thanks for the fresh eyes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top