Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    waiting for a batch file to finish (XP)

    With the help of Hans, I wrote an Access application last week that called a batch file. It iterates through a table that holds the path to several MDBs that copies each MDB then it compacts it then calls a batch file to zip it (WinRAR). Problem is that it doesn't' wait for the batch file to finish before it goes on and therefore it doesn't work. I seems to open multiple Command windows and nothing ends up in the Zip file. How can I get it to wait until the batch file has finished before it moves on?
    Hans, thackyou for the help with getting BLOBS in and out. I eventually found the Stream object in later versions of ADO which is much easier than GetChunk, thought you might like to know.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: waiting for a batch file to finish (XP)

    This is not an Access question, of course. If you don't get a satisfactory reply here, we might move this question to another forum.

    In the meantime, you may find something useful in Windows Scripting Samples.

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: waiting for a batch file to finish (XP)

    I would say it was an Access question! It would depend on what facility is available in Access to invoke a command shell to run (start?) a BATch file, or a command shell to start the BATch file, and whether you can ask Access to wait until the Command Shell terminates. (I know nothing of such arcane matters...!)

    In the BATch file you might need to use EXIT as the final executed statement to terminate the command shell, though!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: waiting for a batch file to finish (XP)

    VBA, the programming language in Access, has the rather basic <img src=/S/pun.gif border=0 alt=pun width=22 height=18> Shell instruction. Shell doesn't have an argument to let code execution wait until the called application has finished. There are many alternatives using Windows API functions that do wait; the scripting site I referred to lists some of them.

  5. #5
    Lounger
    Join Date
    Nov 2002
    Location
    Farnborough, Hampshire, England
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: waiting for a batch file to finish (XP)

    I can't remember where I got this code (I'm certainly not clever enough to write it myself) but it does work well.

    The test subroutine opens Notepad and waits until you close it before continuing to the next line of code.

    Hope that helps!

    <pre>Option Compare Database
    Option Explicit

    Const PROCESS_QUERY_INFORMATION = &H400
    Const SYNCHRONIZE = &H100000
    Const STILL_ACTIVE = &H103&
    Const INFINITE = &HFFFFFFFF

    Private Declare Function OpenProcess Lib "kernel32" _
    (ByVal dwDesiredAccess As Long, _
    ByVal bInheritHandle As Long, _
    ByVal dwProcessId As Long) As Long

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

    Sub TestRunApp()

    apiRunAppThenWait "NOTEPAD.exe", vbNormalFocus
    MsgBox "Application has finished running.", vbInformation, "DONE"

    End Sub


    Public Sub apiRunAppThenWait(strCmdLine As String, intWinMode As Integer)
    On Error GoTo Err_Handler

    Dim hInstance As Long
    Dim hProcess As Long
    Dim lngRetval As Long
    Dim lngExitCode As Long

    ' Get Instance Handle & pass to OpenProcess function:
    hInstance = Shell(strCmdLine, intWinMode)
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
    True, hInstance)

    Do
    lngRetval = GetExitCodeProcess(hProcess, lngExitCode)
    DoEvents
    Loop Until lngExitCode <> STILL_ACTIVE

    Exit_Sub:
    Exit Sub
    Err_Handler:
    Select Case Err.Number
    Case 53 ' File not found
    Beep
    MsgBox "Invalid command line - cannot open application.", _
    vbExclamation, "FILE NOT FOUND"
    Case Else
    Beep
    MsgBox "Error " & Err.Number & ": " & Err.Description
    End Select
    Resume Exit_Sub

    End Sub


    </pre>


  6. #6
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: waiting for a batch file to finish (XP)

    That's great thank you I'll give it a go, can't really test it until all the users have gone home so I'll let you know how it goes.
    and thank you to both John and Hans for your help.

  7. #7
    Lounger
    Join Date
    Nov 2002
    Location
    Farnborough, Hampshire, England
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: waiting for a batch file to finish (XP)

    In case it's useful for anyone, here's a stripped down Access 97 database with the code.

  8. #8
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: waiting for a batch file to finish (XP)

    Work like a treat - thankyou.

Posting Permissions

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