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.
8 3769
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: - Copy and Paste the following API Declarations and Constants into a Standard Code Module:
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
-
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
-
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
-
-
Private Const SYNCHRONIZE = &H100000
-
Private Const INFINITE = -1&
- Copy and Paste the following Sub-Routine Procedure into the same Standard Code Module as the Declarations and Constants:
- Public Sub RunUntilFinished(ByVal sApp As String)
-
Dim lProcID As Long
-
Dim hProc As Long
-
-
'Start the App
-
On Error GoTo ErrHandler
-
-
'Retrieve the Ptrocess ID
-
lProcID = Shell(sApp, vbNormalFocus)
-
-
On Error GoTo 0
-
-
DoEvents
-
-
'Wait indefinately for the App
-
hProc = OpenProcess(SYNCHRONIZE, 0, lProcID)
-
-
If hProc <> 0 Then
-
WaitForSingleObject hProc, INFINITE
-
CloseHandle hProc
-
End If
-
-
Exit_Routine:
-
Exit Sub
-
-
ErrHandler:
-
MsgBox "Error starting " & sApp & vbCrLf & vbCrLf & Err.Description, _
-
vbExclamation, "Error in RunUntilFinished()"
-
Err.Clear
-
Resume Exit_Routine
-
End Sub
- Copy and Paste the following code segment to anywhere appropriate:
- 'Run Windows Calculator
-
Call RunUntilFinished("C:\Windows\System32\Calc.exe")
-
-
'Notepad will not start until Calculator is closed
-
Call RunUntilFinished("C:\Windows\System32\Notepad")
-
-
'Paint will not start until Notepad is closed
-
Call RunUntilFinished("C:\Windows\System32\MSPaint.exe")
- Now that you did all that, just download the Attachment, silly (LOL)!
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.
@billelev
You are quite welcome, let me know how you make out.
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.
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.
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.
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
|
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...
| |