using WaitForSingleObject to launch Access2003 from Access2003 fre

J

Just..in

I have a problem on a few PCs running access 2003 (11.6344.6360) SP1, however
the same code works fine on all others.

In the latest version of a project using Access 2003 (a) it launches another
Access 2003 (b) pausing (a) until (b) is closed. However the second Access
application (b) will not close but hangs, the task manager is required to
close (b) fully allowing (a) to continue.

The application vb code is working on all other PCs, so I'm not sure whether
it’s a pc setup problem or what ?

I have extracted the offending code in db1.mdb (see attachment) you can use
this to test a PC without loading the projects full tool. Clicking on the
buttons…

• OpenAndWaitFor_NotePad_ToClose - opens notepad and pauses until it is
closed this works on all PCs


• OpenAndWaitFor_Access2003_ToClose - opens access2003 .exe application and
pauses until it is closed this is what is locking up for some reason only
certain PCs lock up. The Access 2003 application instance is not able to
close itself when requested. However, when killed through the 'Task Manager'
the focus returns to the db1.mdb and it continues.



Code..


Option Compare Database

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$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function

Sub OpenAndWaitFor_NotePad_ToClose()
Dim retval As Long
retval = ExecCmd("notepad.exe")
MsgBox "Process Finished, Exit Code " & retval
End Sub



Sub OpenAndWaitFor_Access2003_ToClose()
Dim retval As Long

retval = ExecCmd("C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE")
MsgBox "Process Finished, Exit Code " & retval



End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top