General discussion

  • Creator
    Topic
  • #2337691

    XP Batch File will not exit

    Locked

    by haycoconsulting ·

    I have written a short batch file to copy the most current version of a database from a common “library” drive (L:) to the users “user” drive (G:) then open the file in MS Access. The code works fine except it never sees the “exit” command so the cmd prompt window never closes.

    I am thinking it has to do with the ‘environment’. I have tried several variations of ‘setlocal’ and ‘endlocal’ but haven’t made it work so I could be wrong about that.

    Here is the entire batch file (running fromthe g:\ALDS directory – that is a requirement)

    1) xcopy L:\ALDS\Support\ALDSEntry.mdb G:\ALDS\ALDSEntry.mdb /Q /K /Y /D /Z
    2) “c:\Program Files\Microsoft Office\Office\MSACCESS.EXE” G:\ALDS\ALDSEntry.mdb
    3) exit

    (I have inserted line numbers above for clarity. They do not exist in the batch file.)

    I am running XP but my client is running Win2000 Professional. So far everthing has been compatible so if it doesnt work I ass-u-me it won’t work there.

    Anybody know how to make the thing close?

All Comments

  • Author
    Replies
    • #3486024

      XP Batch File will not exit

      by joseph moore ·

      In reply to XP Batch File will not exit

      Does your Access database close, or does it say open?
      The reason I ask is that if the database stays open, then the BAT file never goes down to the 3rd line. When a BAT file opens an application, it stays on that line until the application closes(which sends a signal to Windows; the BAT file picks up this signal and continues onto the next line in the BAT).
      So, if you are copying files, then opening Access to process the files, you need to have Access close down, so the BAT file will continue and process the last line.
      You could write a Macro that opens the Access database, runs whatever process Access needs to do, then closes itself down. That would work for the BAT file to continue.

      hope this helps

      • #3507173

        XP Batch File will not exit

        by haycoconsulting ·

        In reply to XP Batch File will not exit

        Thanks for the tip but in this case I had to do the copy prior to opening the DB (to ensure the latest version of the Entry DB) and leave the DB open.

    • #3485989

      XP Batch File will not exit

      by don christner ·

      In reply to XP Batch File will not exit

      In order to return to the batch file after going to Access, you’ll need to Call the third line. Call tells it to run the executable and then return to the batch file. Otherwise, once it leaves the batch file it will not return.

      Don

    • #3507331

      XP Batch File will not exit

      by beermonster ·

      In reply to XP Batch File will not exit

      Hi,
      actually a call command means to ‘call’ the application, then wait for it to finish – exactly the problem you are having now. Make your second line

      START “startapp” “c:\Program Files\Microsoft Office\Office\MSACCESS.EXE” G:\ALDS\ALDSEntry.mdb

      -all one line obviously. The start command tells the batch file to start the app and then carry on with the next line. The “startapp” part is to get round a quirk of the start command – it views the first string in quotes as a window title,so this stops it confusing your msaccess string (which is in quotes) and trying to make that the window title. Hope this helps…

      • #3507175

        XP Batch File will not exit

        by haycoconsulting ·

        In reply to XP Batch File will not exit

        Thanks BeerMonster – I owe you a beer. But since I doubt you’ll be in Lubbock today, here….have 250 points. Works like a charm and does exactly what I want. Thanks.

    • #3507172

      XP Batch File will not exit

      by haycoconsulting ·

      In reply to XP Batch File will not exit

      This question was closed by the author

Viewing 3 reply threads