Link to home
Start Free TrialLog in
Avatar of jrimmele
jrimmele

asked on

Automatically Run an access query at a specified time

Is there a way to set a query or VBA module to run automatically at a certain time each day?
Avatar of rockiroads
rockiroads
Flag of United States of America image

u could use the windows task scheduler to run a VBa macro

u can pass in parameters like /x macroname in access

alternatively u can create a macro called AutoExec
this will run your code/query then exit the DB
here are the switches for msacess

http://support.microsoft.com/?kbid=209207


as you can see u pass in

/x macroname into msaccess.exe (note full path of msaccess.exe will have to be specified)

Hi jrimmele,

you will have to have a Form that is open at the time when you want this to happen,
I usually have the main Form always open, and you can make the Time interval of the Form to 1 minute (which is 1000 x 60),
and have the following code "On Timer" of the Form

Private Sub Form_Timer()
    Dim TheTime As Date
    TheTime = Format(Now(), "hh:mm")

    Select Case TheTime
        Case #10:30:00 PM#
            DoCmd.openquery "your query name"
    Case Else
            'do nothing
    End Select

End Sub


jaffer
Avatar of jrimmele
jrimmele

ASKER

I was able to get it to work through the task scheduler.  What I was really hoping for was to be able to do was to run the process in the middle of the night sometime, but it doesn't seem to work unless the PC is on - is there a way to get the task to run even if the computer is not on?
urm, no.
if the computer is on, then no programs run

You have to leave it on. I guess what u could add is some code that shuts down the PC after it runs your job
here is an example

http://www.mvps.org/access/api/api0016.htm

urm, typo

if the computer is NOT on, then no programs run

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial