Link to home
Start Free TrialLog in
Avatar of charming
charmingFlag for United States of America

asked on

Scheduling a Macro to run at a specific time of the day

I have a Macro which runs a function in my database.  I needed some module or trigger to automatically call or run this macro every day Monday - Friday at 4:00 PM.  How can I do that?
Thanks
Avatar of harfang
harfang
Flag of Switzerland image

Use the task manager.
You can create a shortcut there that will open the database and run the macro, which should end with "quit access" of course.
Avatar of Billystyx
Billystyx

set the timer event of the main form to 1000 and on the ontimer event of that form put
if time="16:00" Then
'runmacro
endif

Billystyx
The full shorcut could be:

"C:\Program Files\Microsoft Office 97\Office\msaccess.exe" "C:\Boulot\Application.mdb" /x "macMondays"

It can also contain switches for a specifc workgroup information file, user name, password, etc.

Good Luck
actually this might be better - to make sure you catch it:

If time > "16:00" And time < "16:01" Then
'run macro
End If
Actually, Billystyx, you are comparing a date/time with a string. Can you tell me whether the > will be treated alphabetically or numerically?
[pay attention, this question will be part of the exam :) ]

If you do want to use the Time() function, use this:

    If Time > #4:00:00 PM# And Time < #4:01:00 PM# Then

We are allowed to -type- it as "> #16:00#", but VB will convert it to more familiar US time format...

This being said, I still think this is a clear case for the task scheduler... :)

Cheers
it does actually work - I tested it first before posting:)

Billystyx
Avatar of charming

ASKER

This works but the Timer Interval which i set to 1000 must not be high enough because it ran twice within the minute.  Also is there some way to check that the date is between Monday and Friday, perhaps by grabbing the weekday number off of the Current date?  Any ideas?

Here is the code
Private Sub Form_Timer()
If Time > #12:08:00 PM# And Time < #12:09:00 PM# Then
DoCmd.RunMacro "Export_CSV_timer"
End If
End Sub
As far as the Task Scheduler is concerned I have never used it.  Where do I find it and how does that work
The task manager is a part of windows. In Win2000, for example, you will find it under:
   Start / Programs / Accessories / System Tools / Scheduled Tasks
But there are often faster ways to access that list depending on the verision of Windows.

Any shortcut placed there will be run at the requested time and date, with many options.
This will work whether you have the application open or not, as databases are multi-user, so that you can open the same database twice from the same machine, unless you open it in "exclusive" mode, of course.

Good Luck!
Set your timer interval to 30000 where each increment is 1 mS.  30000 = 30 minutes, etc
SOLUTION
Avatar of Billystyx
Billystyx

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
billystyx that will work, but I am still trying to figure out how to do this in the Windows Task Scheduler.  Could I run your code in the Task Scheduler and ignore the Switchboard Event?
I am in the Task Scheduler I see

Run C:\PROGRA~1\MICROS~3\Office\MSACCESS.EXE

Start In C:\PROGRA~1\MICROS~3\Office

Where or how do i execute this code?
My Database name and path is C:\ACH_Development.mdb

Function name is Function ExportCSV()
Not sure - I haven't used it - sorry:)

Billystyx


Also how do you Quit the app after task runs?
ASKER CERTIFIED SOLUTION
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