Executing DOS Batch file from Access and wait until DOS window has closed

Posted on 2009-04-27
Last Modified: 2012-05-06
Hi Experts,

I'm calling a batch file from MSAccess and need to wait until the batch commands have finished.
The batch file ("DnLoadBeta.BAT") connects to an ftp server and executes a script file ("C:\ftp_Script_DnLoad.txt") which download big files.
I need to wait within Access until files have been downloaded (means: until the DOS window of batchfile "DnLoadBeta.BAT" has closed).

Batch file content (FileName: DnLoadBeta.BAT):
     ftp -s:"C:\ftp_Script_DnLoad.txt"
Script file content (FileName: C:\ftp_Script_DnLoad.txt):
     cd users/JPRTL/BetaTool
     get "" "C:\ftp\Application\"

I'm currently calling the batchfile "DnLoadBeta.BAT" from MSAcess with this command:

How can I make MSAccess waiting for completion of Batchfile?

Thanks in advance
Question by:MartinNeubauer
    LVL 10

    Assisted Solution

    One way to handle the "is the process finished yet? question would be to add an extra dummy very small text file to the ftp process which is downloaded last - get access to run a
    do while dir("c:\temp\dummyfile.txt") = ""
    To keep checking until the dummy file is found... Then continue with the data processing ... deleting the dummy file at the end so process is ready to again next time...
    LVL 65

    Accepted Solution

    use shellwait to do this. An example can be found here
    You are shelling but it waits for process to complete

    LVL 38

    Assisted Solution

    by:Jim P.
    I found this somewhere in the depths of time -- very similar to what rocki linked to.

    ' Enter the following Declare statement on one, single line before
    ' anything else in the module:
    Declare Function FindWindow Lib user323 Alias FindWindowA (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
    'Then in your function do 
    Whil FindWindow(vbNullString, "DOS FTP") <> 0 

    Open in new window


    Author Comment

    Hi Jimpen,

    thanks for your input. My system does not find Lib "user323".


    Author Comment

    Hi therealmongoose,

    thanks for this idea. Unfortunately for this specif problem it doesn'T work (cannot writ any flie onto ftp server).

    Author Comment

    Hi Jimpen,
    I checked with "user32" it works now. It does not fit perfectly into my scenario.
    Thanks anyway,


    Author Closing Comment

    All 3 works and I may be able to use them in different scenarios.
    This hint wit meets my requirements for this specific case best.
    Thanks guys for your help.
    LVL 38

    Expert Comment

    by:Jim P.
    Glad to be of assistance. May all your days get brighter and brighter.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now