[AccessD] VBA and DOS Question

Jeremy Toves itsame2000 at sbcglobal.net
Tue Feb 7 14:20:22 CST 2006


Thanks for all those who replied.  It seems like there is no reason I can't make it public.  

Jeremy
   
  

Jim Lawrence <accessd at shaw.ca> wrote:
  Hi Jeremy:

These routines are generally called from a local (in the same module)
function or subroutine that is public. 

Assuming that all this code is in an Access Module by just changing one line
this routine can be accessed from any Form or Report.

'Public Sub ShellAndWait(CommandLine As String) '

HTH
Jim

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jeremy Toves
Sent: February 7, 2006 11:56 AM
To: AccessD
Subject: [AccessD] VBA and DOS Question

I hope somebody can shed some light on this. Sometimes, I'll create and
launch batch files on the fly. I worked around the problem of Access
running over the batch files before they completed by creating a
completion.txt file which my Access database polled for so it knew that the
process finished. That was a less than desirable solution. 

I found a small piece of code that makes an API call to figure out when DOS
is complete before Access procedes. It works great. I'm just curious as to
why the subroutine is private. I don't want to replicate this in each
module I use this API call. Does anybody know why this should be private?
Here is the site I code I found.

Thanks,
Jeremy Toves


http://visualbasic.about.com/od/learnvb6/l/bldykvb6dosa.htm?terms=vb+script+
close+window

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 Declare Function CloseHandle _
Lib "kernel32" ( _
ByVal hObject As Long) _
As Long
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF

Sub Main()
ShellAndWait ("C:\WINDOWS\system32\ping.EXE www.google.com")
End Sub

Private Sub ShellAndWait(CommandLine As String)
Dim ShellId As Long
Dim ShellHandle As Long
ShellId = Shell(CommandLine, vbNormalFocus)
ShellHandle = OpenProcess(SYNCHRONIZE, 0, ShellId)
If ShellHandle <> 0 Then
WaitForSingleObject ShellHandle, INFINITE
CloseHandle ShellHandle
End If
End Sub
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
  




More information about the AccessD mailing list