Gustav Brock
Gustav at cactus.dk
Thu Apr 28 09:52:20 CDT 2005
Hi Jim
And here's another one for this purpose:
Option Compare Database
Option Explicit
Private Const STARTF_USESHOWWINDOW As Long = &H1
Private Const NORMAL_PRIORITY_CLASS As Long = &H20
Private Const INFINITE As Long = -1
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "KERNEL32" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "KERNEL32" ( _
ByVal lpApplicationName As Long, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "KERNEL32" ( _
ByVal hObject As Long) As Long
Public Function ShellExecute( _
ByVal strPathname As String, _
Optional lngAppWinStyle As Long = vbHide) As Boolean
' Start other application and wait for it to finish.
Const cbInheritHandles As Long = 1
Dim typProc As PROCESS_INFORMATION
Dim typStart As STARTUPINFO
Dim lngReturn As Long
On Error GoTo Err_ShellExecute
' Initialize the STARTUPINFO structure:
With typStart
.cb = Len(typStart)
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = lngAppWinStyle
End With
' Load the shelled application.
lngReturn = CreateProcessA(0, strPathname, 0, 0, cbInheritHandles, _
NORMAL_PRIORITY_CLASS, 0, 0, typStart, typProc)
With typProc
If .dwProcessId <> 0 Then
' Wait for the shelled application to finish.
lngReturn = WaitForSingleObject(.hProcess, INFINITE)
' Close both Process and Thread to prevent memory leak.
lngReturn = CloseHandle(.hProcess) And CloseHandle(.hThread)
End If
End With
ShellExecute = True
Exit_ShellExecute:
Exit Function
Err_ShellExecute:
MsgBox "Shell Error: " & Err.Number & ". " & Err.Description, _
vbCritical, _
Err.Source
Resume Exit_ShellExecute
End Function
/gustav
-----Original Message-----
From: Hale, Jim [mailto:Jim.Hale at fleetpride.com]
Sent: Thursday, April 28, 2005 8:58 AM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Unzip Files
<Then I would shell (and wait) to a command line>
how do you pause Access so that it waits until the process is finished?
I
have a process that creates and runs cmd and bat files and then
destroys
them. I have to pause Access so that the files are run before Access
kills
them. My current method is a kludge. In Excel I use the Wait function.
Is
there an analogous function in Access? TIA
Jim Hale