473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to Automate the Running of Multiple Applications

119 100+
I have a number of models that I need to run at regular times each week. The models may be based in Access, Excel or a math based statistics package called R. The models may also be a combination of all three. For example, Access may pull in historical pricing information, this is processed by R, and the results are displayed in Excel.

I can obviously use the Windows "Scheduled Tasks" application to kick the process off at the required time, but I will also need a way of keeping track of each step of a process. For example, if I had the following sequence:

1. Pull data into Access
2. Run R script (via .bat file)
3. Store R data in database
4. Open Excel to plot data

I could potentially achieve 1-3 from VBA in Access, but to run step 4 I would need to know when R had finished so that Excel would not load too early. Similarly, if I start Access from a .bat file (or some other location), then I would need to know when Access had finished pulling in data before starting R, and again when R had finished before starting Excel.

Does anyone know how I can achieve this kind of scheduling? I've thought of posting boolean values to a database table giving an indication of whether or not an application has finished, but that seems like it could be troublesome. I'm not sure what else I could do.

I appreciate this is quite a general question, but I'd be interested in knowing if anyone has had this kind of problem before, or could suggest a solution.
Feb 20 '09 #1
8 3779
ADezii
8,834 Expert 8TB
You can Shell Out and run multiple, independent, processes and wait for each one to finish before you execute the next in sequence, via a little API trickery:
  1. Copy and Paste the following API Declarations and Constants into a Standard Code Module:
    Expand|Select|Wrap|Line Numbers
    1. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    2. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    3. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    4.  
    5. Private Const SYNCHRONIZE = &H100000
    6. Private Const INFINITE = -1&
  2. Copy and Paste the following Sub-Routine Procedure into the same Standard Code Module as the Declarations and Constants:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub RunUntilFinished(ByVal sApp As String)
    2. Dim lProcID As Long
    3. Dim hProc As Long
    4.  
    5. 'Start the App
    6. On Error GoTo ErrHandler
    7.  
    8. 'Retrieve the Ptrocess ID
    9. lProcID = Shell(sApp, vbNormalFocus)
    10.  
    11. On Error GoTo 0
    12.  
    13. DoEvents
    14.  
    15. 'Wait indefinately for the App
    16. hProc = OpenProcess(SYNCHRONIZE, 0, lProcID)
    17.  
    18. If hProc <> 0 Then
    19.   WaitForSingleObject hProc, INFINITE
    20.   CloseHandle hProc
    21. End If
    22.  
    23. Exit_Routine:
    24.   Exit Sub
    25.  
    26. ErrHandler:
    27.   MsgBox "Error starting " & sApp & vbCrLf & vbCrLf & Err.Description, _
    28.           vbExclamation, "Error in RunUntilFinished()"
    29.   Err.Clear
    30.     Resume Exit_Routine
    31. End Sub
  3. Copy and Paste the following code segment to anywhere appropriate:
    Expand|Select|Wrap|Line Numbers
    1. 'Run Windows Calculator
    2. Call RunUntilFinished("C:\Windows\System32\Calc.exe")
    3.  
    4. 'Notepad will not start until Calculator is closed
    5. Call RunUntilFinished("C:\Windows\System32\Notepad")
    6.  
    7. 'Paint will not start until Notepad is closed
    8. Call RunUntilFinished("C:\Windows\System32\MSPaint.exe")
  4. Now that you did all that, just download the Attachment, silly (LOL)!
Feb 21 '09 #2
billelev
119 100+
Awesome...This looks fantastic. I'll give it a try on Monday and let you know how it goes.

Thanks for such a quick response.
Feb 21 '09 #3
ADezii
8,834 Expert 8TB
@billelev
You are quite welcome, let me know how you make out.
Feb 21 '09 #4
NeoPa
32,556 Expert Mod 16PB
Check out the ShellWait() Function for a way to handle this in a basic way. This doesn't mean there's anything wrong with ADezii's code (at all). Sometimes though, it's easier to keep the esoteric, O/S, stuff in a separate module. Develop it then just use it as designed.
Feb 22 '09 #5
billelev
119 100+
ADezii, I have tried your code and it works really well. Many thanks for your input.

I have one other issue, *** Edit *** which can now be found in a new thread.
Feb 23 '09 #6
NeoPa
32,556 Expert Mod 16PB
I have moved the question part of this to another thread (Access Command Line Arguments).

This is for all the usual reasons that asking multiple questions in the same thread is not a good idea. Principal of which is that it gets much better exposure.
Feb 23 '09 #7
FishVal
2,653 Expert 2GB
Command line arguments are not the only and, IMHO, not the most suitable way to trigger some specific action of Access application when opening it via VBA code in other Access application.

Did you consider using application automation?
Feb 23 '09 #8
billelev
119 100+
I have...But only in passing. I'm playing around with the Shell method and then might resort to application automation at a later point. I'm trying to come up with a framework that will work with multiple applications, not just Access, and so Shell might be better in that instance.

In any case, thank you everyone for your help with my automation questions.
Feb 23 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Brad Burke | last post by:
From a windows .Net app, I need to 1) check if MSAccess is already open to a certain Access application. If so, then open a form and find a certain record. 2) If not open, then open MSAccess and...
8
by: nickdu | last post by:
I'm trying to isolate "applications" into their own application domain within a single process. I've quoted applications because it's a logical representation of an application. Basically it...
5
by: Chris Dugan | last post by:
Hi, has anybody come across a solution to running an Access97 database on Windows XP. The situation I have is an Access 97 database that runs perfectly from Win95/98 clients running Access97, the...
6
by: John Galt | last post by:
Does anyone have working code to send a fax from VBA using Outlook.Mailitem? I have tried some examples I have found and they all simply try to use the Fax number as an e-mail address. Thanks in...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
3
by: Carl Johansen | last post by:
I have a big ASP website (used by several thousand car dealers) that is a collection of lots of small and medium-sized applications. Now I want to start adding ASP.NET applications to it. I have...
3
by: Michel | last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for the user; the user open my app, do some works and try to open another instance of my app, I whant to show a message to...
3
by: Olie | last post by:
I have a number of applications that need to access the same object at different times and any one of these programs may be running at any one time. I do not have a specific application that could...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
1
by: asibin2000 | last post by:
I'm having problems with a VB.NET application. We have multiple web applications and we are using a VB.NET program to do a sort of Single Sign On. So this works great, the system automatically...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.