End Task via VBA like when Task Manager is used

M

Manuelauch

How do I end an ACCESS database using VBA just like a User end the task using
the Task Manager. I only need to end a particular database, not the whole MS
ACCESS application.
 
K

Klatuu

Your question isn't clear. What do you meand by end a particular database?
When you say database, you should be meaning an mdb file. When you open an
mdb from Windows, that creates an instance of Access. You can have multiple
instances of Access running. Also, within an instance of Access, you can
open other mdb files when you need to do something with them.

To close the database you are currently in, you use Docmd.Quit, but that
will close that instance of Access and all mdb files it is using, so if you
can give a bit more detail about what you are doing, perhaps we can provide a
correct answer.
 
M

Manuelauch

I mean an instance of ACCESS. What I mean is that I have ACCESS databases
that are running in is a computer in the office. One database is contantly
running and lauch at various pre-set times other ACCESS database for
processing data. This morning an application failed because some one move a
folder where a file was supposed to be placed. Even though I have an error
catcher, some one has to click on the OK button in the Error window, but
there is not one in the office to do so. I want the application that is
constantly running be able to end the database with the error and re-launch
(I use a triggerin the database) the database after I fix the problem. This
is while no body is in the office, so I can do it from home.
Thank you for taking the time to answer the question
 
M

Manuelauch

The main database is open constantly and via the OnTime event of the a form
every 5 minutes a rpcedure runs to checks the current time against the time
set up in a table for various applications. If they match with +/- 5 minutes
it open the corresponding application which automatically start the processing
 
M

Manuelauch

The application that is constantly running, every 5 minutes (via the OnTime
event in a form) checks the current time against times set up a in table for
various databases. If the time is +/- 5 minutes within the current time it
lauches the corresponding database for data processing. The databases have a
procedure to start and quit the process in its own
 
K

Klatuu

it open the corresponding application which automatically start the processing

How? Can you post the code, please?
 
K

Klatuu

I got an email that someone has posted a reply, but nothing came through.

Thinking about it, the only plan I can come up with is to create a table in
the main application that will have fields to identify the app that had the
error.

Then in the applications the main app starts up, change the code so that
rather than presenting a message box, it writes a record in the table the
indicates it failed.

Now, in the time event of the main app. add code to check for errors in the
other apps. If it find an error record, delete the error record and start
the app up again.
 
M

Manuelauch

Changing the codes is not a problem, because I have a table that for every
application it records the line where the error occur and enters the error as
well. That is the way I know what to fix. Once I fix the problem in the
master database (the processing databases are front end databases) I would
like to replace the productive database with the corrected master database
but for that I need to have the one that is open with the error killed or
ended so I can replace it. I have access to the folders in the server to do
all this. To re-run the process I would go in the table and enter a new time
close to the current time so the main application lauches the corrected
database again for processing. This is why I need the codes to kill the error
database.
If you want I can post the codes for your information to see how I lauch the
databases, but that is not the problem I am trying to address
 
K

Klatuu

I know what you are trying to address.
What I was trying to determine is where you are now so I could offer a
suggestion.

One of my suggestions is you modify the applications to quit the application
rather than show a message box. Is there any reason you can't do that?

Another thing you might try is to go to this site:
http://www.mvps.org/access/api/index.html

And see if there are any API calls that will get it done for you.
 
M

Manuelauch

Do not get me wrong. I do not have any problem to show you the code. I will
as a matter of fact. But you are right I can make the application quit when
ever there is an error. So it means that every procedure must have an error
catcher and instaed of invoquing the message box I just enter the application
quit command.

But does it mean that VBA does not have a way to end a task or end a
database that the User will like to kill it for what ever reason?.

Here goes the codes

Private Sub Form_Timer()
On Error GoTo ErrUpdate
Dim sgUpdateTime As Single, sgIntervalTime As Single
Dim stUpdateTime As String, stIndicator As String, stACCESSExeFile As
String, _
stApplicationPathName As String, stFlagFilePathName As String
Dim iCycle As Integer

'Time frequency in which this procedure runs
sgIntervalTime = Me.TimerInterval / 1000 ' TimerInterval is milliseconds
and 'sgIntervalTime' is converted to seconds
'Set variable for MS Access executable file
stACCESSExeFile = DFirst("[MSAccessExeFile]",
"[tblApplicationInformationHolder]")
iCycle = 1

GoTo SkipCodeLine ' skip next block of codes to get variable values on
'Select Case' statement

RepeatLine:

pblProcessingLevel = 2001 ' for error tracking purposes
'Set path and file name of the dummy file used by the lauched databases
to update themselves
stFlagFilePathName = DFirst("[FlagFilePathName]",
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """")
pblProcessingLevel = 2002 ' for error tracking purposes
'Define the time the corresponding applications are to be opened
sgUpdateTime = (CSng(DFirst(stUpdateTime,
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """")))
* 3600
pblProcessingLevel = 2003 ' for error tracking purposes
'If true, Time is within 'sgUpdateTime' and '(sgUpdateTime +
sgIntervalTime)'
If Timer >= sgUpdateTime And Timer <= sgUpdateTime + sgIntervalTime Then
' code Q If
pblProcessingLevel = 2004 ' for error tracking purposes
'Create a dummy file using 'tblApplicationRevison' as a source. The
dummy file is used by the database to update itself
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"tblApplicationRevison", stFlagFilePathName
pblProcessingLevel = 2005 ' for error tracking purposes
'Set path and file name of the database to be opened
stApplicationPathName = DFirst("[FilePath]",
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """") _
& DFirst("[FileName]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """")
pblProcessingLevel = 2006 ' for error tracking purposes
'True, the share drive 'S' may not be available
If Dir(stApplicationPathName) = "" Then GoTo ExitErrUpdate
pblProcessingLevel = 2007 ' for error tracking purposes
'Open MS ACCESS and then the database
Shell stACCESSExeFile & " " & stApplicationPathName, 3
'Exiting the sub ensures that any update will be at least
'sgIntervalTime' minutes apart
GoTo ExitErrUpdate ' the next round for update check will be within
'sgIntervalTime' minutes
End If ' code Q End If

SkipCodeLine:

Select Case iCycle
'UPDATE GEARS INVOICE
Case 1
pblProcessingLevel = 2007 ' for error tracking purposes
iCycle = 2: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsInvoice"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN TABLE APPLICATION
Case 2
pblProcessingLevel = 2008 ' for error tracking purposes
iCycle = 3: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainTable"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE GPS ON TUESDAY
Case 3
pblProcessingLevel = 2010 ' for error tracking purposes
iCycle = 4: stUpdateTime = "[UpdateTime]": stIndicator =
"GPSTable"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Tuesday; therefore do process it
If Weekday(Date, vbMonday) = 2 Then GoTo RepeatLine
GoTo SkipCodeLine
'UPDATE GEARS MATERIAL
Case 4
pblProcessingLevel = 2011 ' for error tracking purposes
iCycle = 5: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsMaterial"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE GEARS PLANNER
Case 5
pblProcessingLevel = 2012 ' for error tracking purposes
iCycle = 6: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsPlanner"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'RUN ORDER CURRENT WEEK PLUS PROCESS IN GEARS ORDER SPEC
(GearsOrderSpecProcessOne)
Case 6
pblProcessingLevel = 2013 ' for error tracking purposes
iCycle = 7: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsOrderSpecProcessOne"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessOne)
Case 7 ' this process runs every day
pblProcessingLevel = 2014 ' for error tracking purposes
iCycle = 8: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainProcessOne"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessTwo)
Case 8 ' this process runs every day
pblProcessingLevel = 2015 ' for error tracking purposes
iCycle = 9: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainProcessTwo"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'RUN ORDER LONG FORECAST PROCESS IN GEARS ORDER SPEC
(GearsOrderSpecProcessTwo)
Case 9
pblProcessingLevel = 2016 ' for error tracking purposes
iCycle = 10: stUpdateTime = "[UpdateTime]": stIndicator
= "GearsOrderSpecProcessTwo"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessThree)
Case 10 ' this process runs every day
pblProcessingLevel = 2017 ' for error tracking purposes
iCycle = 11: stUpdateTime = "[UpdateTime]": stIndicator
= "ApplicationMainProcessThree"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine

End Select
ExitErrUpdate:
Exit Sub
ErrUpdate:
'If true, record the error but does not display warning
If Err.Number = 52 Or Err.Number = 3043 Or Err.Number = 3024 Then
PROCESS_ERROR_STATUS Err.Number, Err.Description, "AutoUpdate", "OK"
Resume ExitErrUpdate
End If
PROCESS_ERROR_STATUS Err.Number, Err.Description, "AutoUpdate"
Resume ExitErrUpdate
End Sub
 
K

Klatuu

There is no way to control an external application from VBA other than to use
the Shell function to start it up. It is not a shortcoming of Access, rather
it is the way Windows works. Each application is independant. Each has an
hwnd property within windows that identifies it, but to be able to close that
application, you would have to be able to capture it's hwnd. That is why I
suggested looking through the API modules available on that site.

But, I would just make sure I used error handling and quit the application.
Since you always want to create a record in the table then quit, I would
write one public sub that would write the record and do the quit and just
call it from all my error handling code.
--
Dave Hargis, Microsoft Access MVP


Manuelauch said:
Do not get me wrong. I do not have any problem to show you the code. I will
as a matter of fact. But you are right I can make the application quit when
ever there is an error. So it means that every procedure must have an error
catcher and instaed of invoquing the message box I just enter the application
quit command.

But does it mean that VBA does not have a way to end a task or end a
database that the User will like to kill it for what ever reason?.

Here goes the codes

Private Sub Form_Timer()
On Error GoTo ErrUpdate
Dim sgUpdateTime As Single, sgIntervalTime As Single
Dim stUpdateTime As String, stIndicator As String, stACCESSExeFile As
String, _
stApplicationPathName As String, stFlagFilePathName As String
Dim iCycle As Integer

'Time frequency in which this procedure runs
sgIntervalTime = Me.TimerInterval / 1000 ' TimerInterval is milliseconds
and 'sgIntervalTime' is converted to seconds
'Set variable for MS Access executable file
stACCESSExeFile = DFirst("[MSAccessExeFile]",
"[tblApplicationInformationHolder]")
iCycle = 1

GoTo SkipCodeLine ' skip next block of codes to get variable values on
'Select Case' statement

RepeatLine:

pblProcessingLevel = 2001 ' for error tracking purposes
'Set path and file name of the dummy file used by the lauched databases
to update themselves
stFlagFilePathName = DFirst("[FlagFilePathName]",
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """")
pblProcessingLevel = 2002 ' for error tracking purposes
'Define the time the corresponding applications are to be opened
sgUpdateTime = (CSng(DFirst(stUpdateTime,
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """")))
* 3600
pblProcessingLevel = 2003 ' for error tracking purposes
'If true, Time is within 'sgUpdateTime' and '(sgUpdateTime +
sgIntervalTime)'
If Timer >= sgUpdateTime And Timer <= sgUpdateTime + sgIntervalTime Then
' code Q If
pblProcessingLevel = 2004 ' for error tracking purposes
'Create a dummy file using 'tblApplicationRevison' as a source. The
dummy file is used by the database to update itself
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"tblApplicationRevison", stFlagFilePathName
pblProcessingLevel = 2005 ' for error tracking purposes
'Set path and file name of the database to be opened
stApplicationPathName = DFirst("[FilePath]",
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """") _
& DFirst("[FileName]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """")
pblProcessingLevel = 2006 ' for error tracking purposes
'True, the share drive 'S' may not be available
If Dir(stApplicationPathName) = "" Then GoTo ExitErrUpdate
pblProcessingLevel = 2007 ' for error tracking purposes
'Open MS ACCESS and then the database
Shell stACCESSExeFile & " " & stApplicationPathName, 3
'Exiting the sub ensures that any update will be at least
'sgIntervalTime' minutes apart
GoTo ExitErrUpdate ' the next round for update check will be within
'sgIntervalTime' minutes
End If ' code Q End If

SkipCodeLine:

Select Case iCycle
'UPDATE GEARS INVOICE
Case 1
pblProcessingLevel = 2007 ' for error tracking purposes
iCycle = 2: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsInvoice"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN TABLE APPLICATION
Case 2
pblProcessingLevel = 2008 ' for error tracking purposes
iCycle = 3: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainTable"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE GPS ON TUESDAY
Case 3
pblProcessingLevel = 2010 ' for error tracking purposes
iCycle = 4: stUpdateTime = "[UpdateTime]": stIndicator =
"GPSTable"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Tuesday; therefore do process it
If Weekday(Date, vbMonday) = 2 Then GoTo RepeatLine
GoTo SkipCodeLine
'UPDATE GEARS MATERIAL
Case 4
pblProcessingLevel = 2011 ' for error tracking purposes
iCycle = 5: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsMaterial"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE GEARS PLANNER
Case 5
pblProcessingLevel = 2012 ' for error tracking purposes
iCycle = 6: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsPlanner"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'RUN ORDER CURRENT WEEK PLUS PROCESS IN GEARS ORDER SPEC
(GearsOrderSpecProcessOne)
Case 6
pblProcessingLevel = 2013 ' for error tracking purposes
iCycle = 7: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsOrderSpecProcessOne"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessOne)
Case 7 ' this process runs every day
pblProcessingLevel = 2014 ' for error tracking purposes
iCycle = 8: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainProcessOne"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessTwo)
Case 8 ' this process runs every day
pblProcessingLevel = 2015 ' for error tracking purposes
iCycle = 9: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainProcessTwo"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'RUN ORDER LONG FORECAST PROCESS IN GEARS ORDER SPEC
(GearsOrderSpecProcessTwo)
Case 9
pblProcessingLevel = 2016 ' for error tracking purposes
iCycle = 10: stUpdateTime = "[UpdateTime]": stIndicator
= "GearsOrderSpecProcessTwo"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessThree)
Case 10 ' this process runs every day
pblProcessingLevel = 2017 ' for error tracking purposes
iCycle = 11: stUpdateTime = "[UpdateTime]": stIndicator
= "ApplicationMainProcessThree"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine

End Select
ExitErrUpdate:
Exit Sub
ErrUpdate:
'If true, record the error but does not display warning
If Err.Number = 52 Or Err.Number = 3043 Or Err.Number = 3024 Then
PROCESS_ERROR_STATUS Err.Number, Err.Description, "AutoUpdate", "OK"
Resume ExitErrUpdate
End If
PROCESS_ERROR_STATUS Err.Number, Err.Description, "AutoUpdate"
Resume ExitErrUpdate
End Sub

Klatuu said:
I know what you are trying to address.
What I was trying to determine is where you are now so I could offer a
suggestion.

One of my suggestions is you modify the applications to quit the application
rather than show a message box. Is there any reason you can't do that?

Another thing you might try is to go to this site:
http://www.mvps.org/access/api/index.html

And see if there are any API calls that will get it done for you.
 
M

Manuelauch

Thanks and I really appriciated you time.

Klatuu said:
There is no way to control an external application from VBA other than to use
the Shell function to start it up. It is not a shortcoming of Access, rather
it is the way Windows works. Each application is independant. Each has an
hwnd property within windows that identifies it, but to be able to close that
application, you would have to be able to capture it's hwnd. That is why I
suggested looking through the API modules available on that site.

But, I would just make sure I used error handling and quit the application.
Since you always want to create a record in the table then quit, I would
write one public sub that would write the record and do the quit and just
call it from all my error handling code.
--
Dave Hargis, Microsoft Access MVP


Manuelauch said:
Do not get me wrong. I do not have any problem to show you the code. I will
as a matter of fact. But you are right I can make the application quit when
ever there is an error. So it means that every procedure must have an error
catcher and instaed of invoquing the message box I just enter the application
quit command.

But does it mean that VBA does not have a way to end a task or end a
database that the User will like to kill it for what ever reason?.

Here goes the codes

Private Sub Form_Timer()
On Error GoTo ErrUpdate
Dim sgUpdateTime As Single, sgIntervalTime As Single
Dim stUpdateTime As String, stIndicator As String, stACCESSExeFile As
String, _
stApplicationPathName As String, stFlagFilePathName As String
Dim iCycle As Integer

'Time frequency in which this procedure runs
sgIntervalTime = Me.TimerInterval / 1000 ' TimerInterval is milliseconds
and 'sgIntervalTime' is converted to seconds
'Set variable for MS Access executable file
stACCESSExeFile = DFirst("[MSAccessExeFile]",
"[tblApplicationInformationHolder]")
iCycle = 1

GoTo SkipCodeLine ' skip next block of codes to get variable values on
'Select Case' statement

RepeatLine:

pblProcessingLevel = 2001 ' for error tracking purposes
'Set path and file name of the dummy file used by the lauched databases
to update themselves
stFlagFilePathName = DFirst("[FlagFilePathName]",
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """")
pblProcessingLevel = 2002 ' for error tracking purposes
'Define the time the corresponding applications are to be opened
sgUpdateTime = (CSng(DFirst(stUpdateTime,
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """")))
* 3600
pblProcessingLevel = 2003 ' for error tracking purposes
'If true, Time is within 'sgUpdateTime' and '(sgUpdateTime +
sgIntervalTime)'
If Timer >= sgUpdateTime And Timer <= sgUpdateTime + sgIntervalTime Then
' code Q If
pblProcessingLevel = 2004 ' for error tracking purposes
'Create a dummy file using 'tblApplicationRevison' as a source. The
dummy file is used by the database to update itself
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"tblApplicationRevison", stFlagFilePathName
pblProcessingLevel = 2005 ' for error tracking purposes
'Set path and file name of the database to be opened
stApplicationPathName = DFirst("[FilePath]",
"tblApplicationGlobalUpdateTimes", "[Indicator] = """ & stIndicator & """") _
& DFirst("[FileName]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """")
pblProcessingLevel = 2006 ' for error tracking purposes
'True, the share drive 'S' may not be available
If Dir(stApplicationPathName) = "" Then GoTo ExitErrUpdate
pblProcessingLevel = 2007 ' for error tracking purposes
'Open MS ACCESS and then the database
Shell stACCESSExeFile & " " & stApplicationPathName, 3
'Exiting the sub ensures that any update will be at least
'sgIntervalTime' minutes apart
GoTo ExitErrUpdate ' the next round for update check will be within
'sgIntervalTime' minutes
End If ' code Q End If

SkipCodeLine:

Select Case iCycle
'UPDATE GEARS INVOICE
Case 1
pblProcessingLevel = 2007 ' for error tracking purposes
iCycle = 2: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsInvoice"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN TABLE APPLICATION
Case 2
pblProcessingLevel = 2008 ' for error tracking purposes
iCycle = 3: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainTable"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE GPS ON TUESDAY
Case 3
pblProcessingLevel = 2010 ' for error tracking purposes
iCycle = 4: stUpdateTime = "[UpdateTime]": stIndicator =
"GPSTable"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Tuesday; therefore do process it
If Weekday(Date, vbMonday) = 2 Then GoTo RepeatLine
GoTo SkipCodeLine
'UPDATE GEARS MATERIAL
Case 4
pblProcessingLevel = 2011 ' for error tracking purposes
iCycle = 5: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsMaterial"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE GEARS PLANNER
Case 5
pblProcessingLevel = 2012 ' for error tracking purposes
iCycle = 6: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsPlanner"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'RUN ORDER CURRENT WEEK PLUS PROCESS IN GEARS ORDER SPEC
(GearsOrderSpecProcessOne)
Case 6
pblProcessingLevel = 2013 ' for error tracking purposes
iCycle = 7: stUpdateTime = "[UpdateTime]": stIndicator =
"GearsOrderSpecProcessOne"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessOne)
Case 7 ' this process runs every day
pblProcessingLevel = 2014 ' for error tracking purposes
iCycle = 8: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainProcessOne"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessTwo)
Case 8 ' this process runs every day
pblProcessingLevel = 2015 ' for error tracking purposes
iCycle = 9: stUpdateTime = "[UpdateTime]": stIndicator =
"ApplicationMainProcessTwo"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine
'RUN ORDER LONG FORECAST PROCESS IN GEARS ORDER SPEC
(GearsOrderSpecProcessTwo)
Case 9
pblProcessingLevel = 2016 ' for error tracking purposes
iCycle = 10: stUpdateTime = "[UpdateTime]": stIndicator
= "GearsOrderSpecProcessTwo"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
'True, it is Saturday or Sunday; therefore do not process it
If Weekday(Date, vbMonday) = 6 Or Weekday(Date, vbMonday) = 7
Then GoTo SkipCodeLine
GoTo RepeatLine
'UPDATE MAIN PROCESS APPLICATION (ApplicationMainProcessThree)
Case 10 ' this process runs every day
pblProcessingLevel = 2017 ' for error tracking purposes
iCycle = 11: stUpdateTime = "[UpdateTime]": stIndicator
= "ApplicationMainProcessThree"
'True, this process is turn off; therefore do not process it
If DFirst("[ProcessFlag]", "tblApplicationGlobalUpdateTimes",
"[Indicator] = """ & stIndicator & """") = "NO" Then GoTo SkipCodeLine
GoTo RepeatLine

End Select
ExitErrUpdate:
Exit Sub
ErrUpdate:
'If true, record the error but does not display warning
If Err.Number = 52 Or Err.Number = 3043 Or Err.Number = 3024 Then
PROCESS_ERROR_STATUS Err.Number, Err.Description, "AutoUpdate", "OK"
Resume ExitErrUpdate
End If
PROCESS_ERROR_STATUS Err.Number, Err.Description, "AutoUpdate"
Resume ExitErrUpdate
End Sub

Klatuu said:
I know what you are trying to address.
What I was trying to determine is where you are now so I could offer a
suggestion.

One of my suggestions is you modify the applications to quit the application
rather than show a message box. Is there any reason you can't do that?

Another thing you might try is to go to this site:
http://www.mvps.org/access/api/index.html

And see if there are any API calls that will get it done for you.

--
Dave Hargis, Microsoft Access MVP


:

Changing the codes is not a problem, because I have a table that for every
application it records the line where the error occur and enters the error as
well. That is the way I know what to fix. Once I fix the problem in the
master database (the processing databases are front end databases) I would
like to replace the productive database with the corrected master database
but for that I need to have the one that is open with the error killed or
ended so I can replace it. I have access to the folders in the server to do
all this. To re-run the process I would go in the table and enter a new time
close to the current time so the main application lauches the corrected
database again for processing. This is why I need the codes to kill the error
database.
If you want I can post the codes for your information to see how I lauch the
databases, but that is not the problem I am trying to address

:

I got an email that someone has posted a reply, but nothing came through.

Thinking about it, the only plan I can come up with is to create a table in
the main application that will have fields to identify the app that had the
error.

Then in the applications the main app starts up, change the code so that
rather than presenting a message box, it writes a record in the table the
indicates it failed.

Now, in the time event of the main app. add code to check for errors in the
other apps. If it find an error record, delete the error record and start
the app up again.

--
Dave Hargis, Microsoft Access MVP


:

The main database is open constantly and via the OnTime event of the a form
every 5 minutes a rpcedure runs to checks the current time against the time
set up in a table for various applications. If they match with +/- 5 minutes
it open the corresponding application which automatically start the processing

:

How do I end an ACCESS database using VBA just like a User end the task using
the Task Manager. I only need to end a particular database, not the whole MS
ACCESS application.
 
Top