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
rep
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
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
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