473,325 Members | 2,805 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,325 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 3769
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.