Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    66

    Unanswered: exit program from VBA ( batch processing )

    HI,

    I'm running an Access macro from MYSCRIPT.BAT file. The command line is something like:

    my_db.mdb /x my_sub

    The intention is to perform a macro, and then close Ms-Access completely. This works up to one point: Access does indeed come up, the subroutine executes well.

    But at the end of my VBA code, I need to close Ms-Access completely, so that execution passes to the next command in the BAT file. I have tried the following, without any success:

    Application.CloseCurrentDatabase
    Application.Quit
    DoCmd.Quit

    Any ideas ?

    Perhaps the problem is I have no Form at all in my application. I'm doing plain batch processing, but I don't mind something coming up on the screen for a few moments, as long as it goes away.

    Andrew

  2. #2
    Join Date
    Nov 2003
    Posts
    267
    If you are running a macro... Try adding the Quit Action to the macro and see what happens.

    S-

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Re: exit program from VBA ( batch processing )

    Originally posted by andrewsc
    HI,

    I'm running an Access macro from MYSCRIPT.BAT file. The command line is something like:

    my_db.mdb /x my_sub

    The intention is to perform a macro, and then close Ms-Access completely. This works up to one point: Access does indeed come up, the subroutine executes well.

    But at the end of my VBA code, I need to close Ms-Access completely, so that execution passes to the next command in the BAT file. I have tried the following, without any success:

    Application.CloseCurrentDatabase
    Application.Quit
    DoCmd.Quit

    Any ideas ?

    Perhaps the problem is I have no Form at all in my application. I'm doing plain batch processing, but I don't mind something coming up on the screen for a few moments, as long as it goes away.

    Andrew
    Using the sendKeys you can send Ctr+F4

  4. #4
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    66
    I also came upon the solution with the macro, but that by itself was not sufficient. If I did a QUIT action from the macro, a system-modal message box came up, complaining the MDB file cannot be found. This of course held back my batch.

    I figured that the Microsoft exit logic was written for graphical environment, so I must have a form opening and closing. The final solution looks like this:

    - use AutoExec macro, instead of the /X swith on the command line

    - the AutoExec macro calls my VBA code, which does the main work

    - after the work is complete, the VBA code does:
    DoCmd.OpenForm my_form.

    - after this, control returns from the VBA code to the macro. This probably gives time for the form to come up

    - next, the AutoExec macro does
    Close my_form

    - in my_form, the "close" event has the following code:
    Application.quit

    A rather contorted way, I must admit, but it works. I guess the trick was to allow the form to fully come up, forcing a few context switches in between.

    Andrew

Posting Permissions

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