Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process is not finishing

Status
Not open for further replies.

Pugs320

Technical User
Jan 29, 2002
19
US
What code can I insert in a module running several processes, that will allow a process to finish B4 moving to next process. Right now I am not getting desired results because 1 process is stepping on the other.
 
Something like this may help:

' this code was lifted from the internet.
' purpose: to shell out a command and wait until
' the command is done.

Option Compare Database
Option Explicit

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 String, 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 String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1

Public Function ExecCmd(CmdLine As String)
DoCmd.Hourglass True
Dim Proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO

Start.cb = Len(Start)

Dim ret As Long
ret = CreateProcessA(vbNullString, CmdLine, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, Start, Proc)

ret = WaitForSingleObject(Proc.hProcess, INFINITE)
Call GetExitCodeProcess(Proc.hProcess, ret)
Call CloseHandle(Proc.hThread)
Call CloseHandle(Proc.hProcess)
ExecCmd = ret
DoCmd.Hourglass False
End Function


 
I wouldn't even know where to begin with this code. If this is the way to do this, can someone give me an indication where to place this code in the module.
 
1) Create a module
2) Paste the supplied code into the module
3) compile/save the module
4) use ExecCmd(<filename>) to run a program, e.g.
ExecCmd(&quot;c:\winnt\system32\notepad.exe&quot;)

ExecCmd will wait until the process is complete before returning control to your visual basic code.
 
Thanks, I will be working with your suggestion as soon as the rest of the emergencies at work are addressed. I will let you know the results.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top