Question : Autorun Controller for Access applications

Hi all,

We currently have numerous (20+) access applications that are used to generate various reports. Due to IT restrictions Access 2003 is the best application we can use for these reports. The below code is in an access application that is set to run OnOpen from a scheduled task. I'm having 2 problems that I dont know how to address.

1) one of the applications has an OnOpen that is deleteing old data. This causes an error since I'm trying to start a seperate macro while that one is running.

2) almost all of these applications compact on close. the AccessApp.DoCmd.close will cause an error application cannot be closed. what can I do to make it wait until the compact is finished before moving on?

I'm trying to automate these reports since the process a couple people go through every morning is. Open Database, Click Run, Close application, rinse and repeat. this takes up most of the morning for 2 or more people. Automating this would save us a ton of time..

Thanks.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Dim AccessApp
    Set AccessApp = CreateObject("Access.Application")
    AccessApp.Visible = True
    AccessApp.OpenCurrentDatabase ("MyDBLocation.mdb")
    AccessApp.DoCmd.SetWarnings False
    AccessApp.DoCmd.RunMacro "macAutoRun"
    AccessApp.DoCmd.Quit
    AccessApp.DoCmd.Close
    Set AccessApp = Nothing
 
    Set AccessApp = CreateObject("Access.Application")
    AccessApp.Visible = True
    AccessApp.OpenCurrentDatabase ("MySecondDBLocation.mdb")
    AccessApp.DoCmd.SetWarnings False
    AccessApp.DoCmd.RunMacro "macAutoRun"
    AccessApp.DoCmd.Quit
    AccessApp.DoCmd.Close
    Set AccessApp = Nothing

Answer : Autorun Controller for Access applications

Try
    AccessApp.DoCmd.Quit
    DoEvents
    AccessApp.DoCmd.Close

or
    Dim lngStartTime As Long

    AccessApp.DoCmd.Quit
    lngStartTime = Timer ()
    Do
          DoEvents
    Loop Until Timer () - lngStartTime > 5
    AccessApp.DoCmd.Close

Change 5 to the number of seconds you need to wait
Random Solutions  
 
programming4us programming4us