By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

CMD window will not close after Batch file executes

P: n/a
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

It appears that the batch file does not proceed any further than the
code:

"My Access DB.mdb"

ie.

echo off
cls
echo "Hit enter to backup"
pause
del ...
copy ...
ren ...
echo "done - Hit enter to open database"
pause
"My Access DB.mdb"
echo "This line will execute after My Access DB.mdb is closed"
pause
Exit

I use: Call Shell("cmd.exe /c " & tmpBatch, 1) to execute the shell.
I have tried many variations with identical results. If I remove the:
"My Access DB.mdb" line, then the cmd window completely executes and
closes. If I leave it in there, it will open the database as desired,
and will remain open UNTIL I close the access database. Once the DB
is closed, the batch file finishes executing the code after "My
Access DB.mdb". I do not want this window to remain open during this
period as the batch file needs to be deleted after the DB opens.

Any help would be appreciated.

Thanks
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Bill wrote:
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

It appears that the batch file does not proceed any further than the
code:

"My Access DB.mdb"

ie.

echo off
cls
echo "Hit enter to backup"
pause
del ...
copy ...
ren ...
echo "done - Hit enter to open database"
pause
"My Access DB.mdb"
echo "This line will execute after My Access DB.mdb is closed"
pause
Exit

I use: Call Shell("cmd.exe /c " & tmpBatch, 1) to execute the shell.
I have tried many variations with identical results. If I remove the:
"My Access DB.mdb" line, then the cmd window completely executes and
closes. If I leave it in there, it will open the database as desired,
and will remain open UNTIL I close the access database. Once the DB
is closed, the batch file finishes executing the code after "My
Access DB.mdb". I do not want this window to remain open during this
period as the batch file needs to be deleted after the DB opens.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't include the cmd.exe /c in the Shell() function. Just use the
batch file name. Invoking a batch file will automatically open the
Command window. If you're worried about the command window displaying
while the Access app is running: instead of a Shell WindowStyle of 1,
use 0 (zero) to hide the command window: Shell("batch.bat" 0).

In earlier versions of Windows you could edit the properties of a Batch
file to "close window on completion." This would cause the command
window to close when the batch file finished (whether or not "exit" was
the last command). I can't see that option in Windows XP. Ah,
progress....

- --
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQG4y64echKqOuFEgEQKgkACg0Iy36W2SO/+tnf+OKCHtDzXETIQAoKJk
hu4LP8gCvSngep/C2CYbTlVY
=gwTb
-----END PGP SIGNATURE-----

Nov 12 '05 #2

P: n/a
Using just the filename only without the cmd.exe was one of my various
options that I had tried with the identical result.
I also tried Command.com /c file.bat, I tried it without the /c and a few
other ways all with identical results.

I am on NT if that makes any difference.

Thanks...Any other suggestions?

Bill, aka Mr. "Can't close a cmd window"

"MGFoster" <me@privacy.com> wrote in message
news:Op*******************@newsread2.news.pas.eart hlink.net...
Bill wrote:
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

It appears that the batch file does not proceed any further than the
code:

"My Access DB.mdb"

ie.

echo off
cls
echo "Hit enter to backup"
pause
del ...
copy ...
ren ...
echo "done - Hit enter to open database"
pause
"My Access DB.mdb"
echo "This line will execute after My Access DB.mdb is closed"
pause
Exit

I use: Call Shell("cmd.exe /c " & tmpBatch, 1) to execute the shell.
I have tried many variations with identical results. If I remove the:
"My Access DB.mdb" line, then the cmd window completely executes and
closes. If I leave it in there, it will open the database as desired,
and will remain open UNTIL I close the access database. Once the DB
is closed, the batch file finishes executing the code after "My
Access DB.mdb". I do not want this window to remain open during this
period as the batch file needs to be deleted after the DB opens.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't include the cmd.exe /c in the Shell() function. Just use the
batch file name. Invoking a batch file will automatically open the
Command window. If you're worried about the command window displaying
while the Access app is running: instead of a Shell WindowStyle of 1,
use 0 (zero) to hide the command window: Shell("batch.bat" 0).

In earlier versions of Windows you could edit the properties of a Batch
file to "close window on completion." This would cause the command
window to close when the batch file finished (whether or not "exit" was
the last command). I can't see that option in Windows XP. Ah,
progress....

- --
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQG4y64echKqOuFEgEQKgkACg0Iy36W2SO/+tnf+OKCHtDzXETIQAoKJk
hu4LP8gCvSngep/C2CYbTlVY
=gwTb
-----END PGP SIGNATURE-----

Nov 12 '05 #3

P: n/a
Try calling Access asynchronously using the Start command, something like:

Start "My Access DB.mdb"

Also, you might put a CLS at the end of the batch file after any echo or
pause commands, so nothing is onscreen to view.

- Steve
"sixsoccer" <si*******@yahoo.com> wrote in message
news:78********************@news01.bloor.is.net.ca ble.rogers.com...
Using just the filename only without the cmd.exe was one of my various
options that I had tried with the identical result.
I also tried Command.com /c file.bat, I tried it without the /c and a few
other ways all with identical results.

I am on NT if that makes any difference.

Thanks...Any other suggestions?

Bill, aka Mr. "Can't close a cmd window"

"MGFoster" <me@privacy.com> wrote in message
news:Op*******************@newsread2.news.pas.eart hlink.net...
Bill wrote:
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

It appears that the batch file does not proceed any further than the
code:

"My Access DB.mdb"

ie.

echo off
cls
echo "Hit enter to backup"
pause
del ...
copy ...
ren ...
echo "done - Hit enter to open database"
pause
"My Access DB.mdb"
echo "This line will execute after My Access DB.mdb is closed"
pause
Exit

I use: Call Shell("cmd.exe /c " & tmpBatch, 1) to execute the shell.
I have tried many variations with identical results. If I remove the:
"My Access DB.mdb" line, then the cmd window completely executes and
closes. If I leave it in there, it will open the database as desired,
and will remain open UNTIL I close the access database. Once the DB
is closed, the batch file finishes executing the code after "My
Access DB.mdb". I do not want this window to remain open during this
period as the batch file needs to be deleted after the DB opens.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't include the cmd.exe /c in the Shell() function. Just use the
batch file name. Invoking a batch file will automatically open the
Command window. If you're worried about the command window displaying
while the Access app is running: instead of a Shell WindowStyle of 1,
use 0 (zero) to hide the command window: Shell("batch.bat" 0).

In earlier versions of Windows you could edit the properties of a Batch
file to "close window on completion." This would cause the command
window to close when the batch file finished (whether or not "exit" was
the last command). I can't see that option in Windows XP. Ah,
progress....

- --
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQG4y64echKqOuFEgEQKgkACg0Iy36W2SO/+tnf+OKCHtDzXETIQAoKJk
hu4LP8gCvSngep/C2CYbTlVY
=gwTb
-----END PGP SIGNATURE-----


Nov 12 '05 #4

P: n/a
Ike
i have had a similar problem. the solution depended upon the version
of windows i was using. try putting the path in the start command.

start c:"my db.mdb"

i know it sounds silly but it worked for me.

"Stephen K. Young" <s k y @ stanleyassociates . com> wrote in message news:<c4*************@ID-65843.news.uni-berlin.de>...
Try calling Access asynchronously using the Start command, something like:

Start "My Access DB.mdb"

Also, you might put a CLS at the end of the batch file after any echo or
pause commands, so nothing is onscreen to view.

- Steve
"sixsoccer" <si*******@yahoo.com> wrote in message
news:78********************@news01.bloor.is.net.ca ble.rogers.com...
Using just the filename only without the cmd.exe was one of my various
options that I had tried with the identical result.
I also tried Command.com /c file.bat, I tried it without the /c and a few
other ways all with identical results.

I am on NT if that makes any difference.

Thanks...Any other suggestions?

Bill, aka Mr. "Can't close a cmd window"

"MGFoster" <me@privacy.com> wrote in message
news:Op*******************@newsread2.news.pas.eart hlink.net...
Bill wrote:

> 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
>
> It appears that the batch file does not proceed any further than the
> code:
>
> "My Access DB.mdb"
>
> ie.
>
> echo off
> cls
> echo "Hit enter to backup"
> pause
> del ...
> copy ...
> ren ...
> echo "done - Hit enter to open database"
> pause
> "My Access DB.mdb"
> echo "This line will execute after My Access DB.mdb is closed"
> pause
> Exit
>
> I use: Call Shell("cmd.exe /c " & tmpBatch, 1) to execute the shell.
> I have tried many variations with identical results. If I remove the:
> "My Access DB.mdb" line, then the cmd window completely executes and
> closes. If I leave it in there, it will open the database as desired,
> and will remain open UNTIL I close the access database. Once the DB
> is closed, the batch file finishes executing the code after "My
> Access DB.mdb". I do not want this window to remain open during this
> period as the batch file needs to be deleted after the DB opens.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't include the cmd.exe /c in the Shell() function. Just use the
batch file name. Invoking a batch file will automatically open the
Command window. If you're worried about the command window displaying
while the Access app is running: instead of a Shell WindowStyle of 1,
use 0 (zero) to hide the command window: Shell("batch.bat" 0).

In earlier versions of Windows you could edit the properties of a Batch
file to "close window on completion." This would cause the command
window to close when the batch file finished (whether or not "exit" was
the last command). I can't see that option in Windows XP. Ah,
progress....

- --
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQG4y64echKqOuFEgEQKgkACg0Iy36W2SO/+tnf+OKCHtDzXETIQAoKJk
hu4LP8gCvSngep/C2CYbTlVY
=gwTb
-----END PGP SIGNATURE-----


Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.