Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shell & wait (VBA - Access 97)

    I need to run a DOS app, and wait for it to complete processing before proceeding with the VBA code. Found some code "somewhere" (can't remember the source) that accomplishes 99% of my requirements -- only additional requirement is for the DOS window to appear and stay visible. I want to have the user close it manually or press ESC or whatever. At present, it simply runs, flickers briefly, then disappears, so any messages from the DOS program are lost.

    This is the code that I am using. How do I tweak it for the DOS window to remain visible? TIA.



    Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal _
    dwAccess As Long, ByVal fInherit As Integer, ByVal hObject _
    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



    Function LaunchApp32(MYAppname As String) As Integer
    On Error Resume Next
    Const SYNCHRONIZE = 1048576
    Const INFINITE = -1&
    Dim ProcessID&
    Dim ProcessHandle&
    Dim Ret&

    LaunchApp32 = -1
    ProcessID = Shell(MYAppname, vbNormalFocus)
    If ProcessID <> 0 Then
    ProcessHandle = OpenProcess(SYNCHRONIZE, True, ProcessID&)
    Ret = WaitForSingleObject(ProcessHandle, INFINITE)
    Ret = CloseHandle(ProcessHandle)

    Else
    MsgBox "ERROR : Unable to start " & MYAppname
    LaunchApp32 = 0
    End If
    End Function
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Shell & wait (VBA - Access 97)

    What happens if you comment out the line

    Ret = CloseHandle(ProcessHandle)

    Oh, and what has this to do with Access 97?
    Charlotte

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shell & wait (VBA - Access 97)

    Commenting the line makes no difference.

    The host application is Access 97. I included that info in case it makes a difference where the function was called from.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Shell & wait (VBA - Access 97)

    Hi,
    What OS are you running? Do you use command.com or cmd.exe for your DOS shell? If the latter, you could use something like:
    <pre>Sub testdos()
    LaunchApp32 "cmd.exe /k ""C:test.bat"""
    End Sub
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •