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.e xe" "C:\Access\TESTDB\TESTDB.m db" /x MACRO1
Once the macro completes I'd like to close the database and Microsoft Access.
Here is the code from my batch file:
@echo off
"C:\Program Files\Microsoft Office\OFFICE11\msaccess.e
Once the macro completes I'd like to close the database and Microsoft Access.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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....
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....
ASKER
Based on the code I provided initially, how can I create a command in task scheduler to acheive the same outcome?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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.
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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?
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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...
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...
ASKER
I think I may have found the culprit...
I'll let you know in a minute....
I'll let you know in a minute....
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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....
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....
ASKER
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... ;)
Yep You should suggest that I do that alright... ;)
Glad you got it figured out.
OM Gang
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.
ASKER