Link to home
Create AccountLog in
Avatar of Stephen Daugherty
Stephen Daugherty

asked on

Batch File Exit Code

I have a incredibly simple batch file that calls MicroSoft Acces, opens a specified database, then calls a Macro within the opened database. Once this macro completes, I want to use the batch file to terminate Access. What code can I use to do this?

Here is the code from my batch file:

@echo off
"C:\Program Files\Microsoft Office\OFFICE11\msaccess.exe" "C:\Access\TESTDB\TESTDB.mdb" /x MACRO1

Once the macro completes I'd like to close the database and Microsoft Access.

SOLUTION
Avatar of omgang
omgang
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Stephen Daugherty
Stephen Daugherty

ASKER

That's what i have been doing, but suddenly it is no longer working. Instead of quitting the database like it should it is hanging up and remaining open with a 25% utilization on the server's CPU. The batch is set in task scheduler to run everyday, but because the app is never successfully closing the scheduled job does not run. So in essence I am looking for a new way to kill the database once the macro runs.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The thing is that I have been manually firing the batch file all day and watching what it is doing. I am using it to create reports and send emails out to various people. I watch all the messages go and then Access just sits there open with no prompts.

I took special pains to prevent prompts, I unchecked all three confimation boxes in the options dialog and I also added VB code to kill prompts and the beginning of all my Form_Open events:

DoCmd.SetWarnings False

I guess I'll try a Compact and Repair....
Based on the code I provided initially, how can I create a command in task scheduler to acheive the same outcome?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
It runs other macros that clears and updates local tables with new information, then it outputs the reports to directories on the drive, then it performs a series of Form Open commands and each for has an "On Open" event that sends the reports based on different DAO recordsets via SMTP call. All of this is working fine. The reports all get created and emailed, but when the database reaches the "QUIT" command it just locks up.

I even tried creating a seperate Macro that has nothing but a quit command and calling it in the last line of the last "On Open" event that I am running, but when it is told to quit the Application just freezes then the CPU cranks up to 25% and just sits there.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Ok, I tested the Macro that contains only the quit command and it does indeed close the Database successfully. However, I went back through my database and everywhere I had a variable declared I followed up with a

Set variablename = Nothing

statement to free up any memory being utilized by the variables. I also ensured that the commands were present on all recordsets to close them. e.g. - rs.Close

This database has been operating succesfully for a few months now and all of a sudden this problem came up. I don't think there is anything in any of my routines that would cause this unless someone got in there and made some minuscule change to one or more of them...

Is there a VBA string I can add to the end of the last routine to kill anything still running in the database?

SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Absolutely no design changes are being made. I enabled all prompts just to make sure of it.

And I already have the Set rs = Nothing and Set db = Nothing in the code after the rs.close command.

I compacted and repaired again, but it did not help...
I think I may have found the culprit...

I'll let you know in a minute....
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Dang!!

I just broke my master Macro into 10 seperate macros, then created 10 seperate batch files designed to call access, the database, then the respective macro I wanted to test.

I narrowed the problem down to one macro, that contained an Open Form command (which launches a Macro to synchronize a table), a RunMacro command that Launches a macro that synchronizes another table, then annother OpenForm command that creates and emails the reports based on the second table that got synchronized, then a Quit command to close the app and terminate the batch.

Here's strange part...

I broke the Open Form command that performs the first synchronization out of the macro and created a new macro that contained only the OPen Form command that lauches the first table sync, and a Quit command.

Then I created a batch file to call that macro, and it ran, terminated the app, and closed the batch.

Then I re-ran the batch file that i had modified to test the macro I previously removed the Open Form event that launches the first table sync, and it also ran successfully and terminated the app and batch.

But if I put them back together, the *&^*)(^ thing hangs up....

I am scratching my head on this one... Is there a way to put a Pause between the first OPenForm Command and the subsequent commands in the Macro? I think if I can make it pause for 10 or 15 seconds it just might work....
Ok, how about you suggest that maye I should let the batch call the Macro that launches the first table sync, with the last line of the procedure to close the form, then create and Form_Close() event that will launch the Macro that runs everything else...

Yep You should suggest that I do that alright... ;)
Glad you got it figured out.
OM Gang
I had a similar problem like his.  If you call a function in the macro I think Access opens up a second thread and it will continue executing the next command in the macro.