473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Scheduled Task to Run Macros

Hi All,

I am wondering if there is another way to run macros at a scheduled time?

Current I have setup Windows Scheduled Tasks but each time they run they open the database and then close it. But I want to be able to leave the database open and still have the macros run.

I have the following Macros:

Run_Weekly - which appends into another table and then deletes the main table and prints
Run_Monthly - which does the same as above but deletes the Weekly Table
Run_Yearly - which prints the yearly report and deletes the data in the yearly table

is it possible for this to be done via VBA? I'm just not sure who I specify to run once a week, month and year.

There might not be an easy answer but any help would appreciated.

Thank You
Dec 10 '11 #1

✓ answered by NeoPa

I guess you have the timer checking a specific, hard-coded, time period. What I would suggest is a table with multiple records (one for each trigger point) that is processed by the timer code. Due to the latency of checking the data this should be somewhat less frequent than once every second certainly. Only you can decide the best balance based on what you know is required, but for daily / weekly / monthly / yearly processes I'd start that at around ten minutes and work from there.

Also due to latency, I would work on the basis of disabling the timer while any particular process is under way. As soon as it finishes the Timer should be re-enabled.

Table = [tblSchedule]
Expand|Select|Wrap|Line Numbers
  1. Field             Type        Index  Comment
  2. jobID             AutoNumber    PK
  3. jobName           String
  4. jobFreq           String             For description only
  5. jobProc           String             Name of valid procedure with available scope
  6. jobParams         String             Parameters, if required, for jobProc
  7. jobNext           DateTime           Absolute time of next run
  8. jobInterval       String             To match 1st param of DateAdd()
  9. jobIntCount       Numeric            To match 2nd param of DateAdd()
  10. jobFromNext       Boolean            True means Add to Next
  11.                                      False means add to Now() after process
You can trigger the process by using the Run() method and passing jobProc and jobParams as parameters.

Does this all start to fit into place now for you?

11 3277
NeoPa
32,556 Expert Mod 16PB
Just to be clear here Will, you're talking about a database which is literally left running all through the year yes? 24/7 52 weeks in the year?

Just to start the ball rolling, Invoking a Database From the Command Line can help you with scheduling jobs from the O/S. If it really is required from a running database just confirm the answers to the questions above and we can look into it for you. There is certainly a way to do it.
Dec 10 '11 #2
Hey NeoPa,

Ideally yes, I mean the computer is set to sleep in the evening, but if it needs to remain open and running for me to able to to schedule macros to run via VBA then I can do that, I have created a clock-in, clock-out database where our customers can sign themselves in and out. At the mo windows scheduler is doing the work, so its set to close the database at 18:00 so the macros can run as its has to open the database, the macros don't seem to run when the database is open!

is it a problem for the database to run 24/7? If you have a better Idea I'm open to suggestions :)
Dec 10 '11 #3
NeoPa
32,556 Expert Mod 16PB
Give me a few minutes to gather my thoughts. Certainly scheduling can be done from within Access too, as long as the form managing it stays open (which is easy enough to ensure). I would suggest this form close the database whenever it detects itself (the form) being closed. That way you will always know whether or not the code is active. Alternatively, for full confidence, a flash of something should occur every n seconds to notify the operator that all is still active if that's required. Forms can stay visible even after the project has been reset. Let me know if this is an issue while I make preparations to explain how it all should work.
Dec 10 '11 #4
I have a 'Welcome Screen' form that remains open, with the options to sign in and sign out. that form can't be closed unless a pin number is entered to execute the form close command. I have disabled the right click and shortcut menu along with the close button.

on the welcome form I have a timer event that checks the time and if its between 17:00 and 17:06 it will run the end of day, which appends the Daily table into the Weekly table and then prints the daily report.

But currently as the windows scheduler runs that macros I have to set the database to close at 18:00 to enable the macros to run!

I have also disabled the ALT + F4 keyboard shortcut to prevent people being able to close the application.

I think I have just repeated myself there!
Dec 10 '11 #5
NeoPa
32,556 Expert Mod 16PB
You already have the Timer process triggering some processes. Where is your difficulty exactly with getting them all triggered in the same way?
Dec 10 '11 #6
I am having trouble specifying each macro to fire at a specific time, like once a week, once a month and one a year.

I'm not even sure if thats possible!
Dec 10 '11 #7
NeoPa
32,556 Expert Mod 16PB
I guess you have the timer checking a specific, hard-coded, time period. What I would suggest is a table with multiple records (one for each trigger point) that is processed by the timer code. Due to the latency of checking the data this should be somewhat less frequent than once every second certainly. Only you can decide the best balance based on what you know is required, but for daily / weekly / monthly / yearly processes I'd start that at around ten minutes and work from there.

Also due to latency, I would work on the basis of disabling the timer while any particular process is under way. As soon as it finishes the Timer should be re-enabled.

Table = [tblSchedule]
Expand|Select|Wrap|Line Numbers
  1. Field             Type        Index  Comment
  2. jobID             AutoNumber    PK
  3. jobName           String
  4. jobFreq           String             For description only
  5. jobProc           String             Name of valid procedure with available scope
  6. jobParams         String             Parameters, if required, for jobProc
  7. jobNext           DateTime           Absolute time of next run
  8. jobInterval       String             To match 1st param of DateAdd()
  9. jobIntCount       Numeric            To match 2nd param of DateAdd()
  10. jobFromNext       Boolean            True means Add to Next
  11.                                      False means add to Now() after process
You can trigger the process by using the Run() method and passing jobProc and jobParams as parameters.

Does this all start to fit into place now for you?
Dec 10 '11 #8
Yes thank you! I will give it a go
Dec 10 '11 #9
NeoPa
32,556 Expert Mod 16PB
I suppose some dummy data for that table might help you to form a picture of what's required (It's a bit wide so I've fitted it on two lines) :

Table = [tblSchedule]
Expand|Select|Wrap|Line Numbers
  1. jobName             jobProc           jobNext       jobIntCount
  2.        jobFreq            jobParams        jobInterval       jobFromNext
  3. Management Reports  fMgmtRpts    #12/12/2011 08:00#      1
  4.        Weekly                Null               w                 True
  5. Yearly Reports      fYlyRpts     #01/01/2012 08:00#      1
  6.        Yearly                Null              yyyy               True
  7. Usage Log           fUsageLog    #12/10/2011 13:20#      10
  8.        Ten mins              Null               n                 False
I've also assumed dates in USA format for you. This is only some example data, to illustrate some of the options you could use.
Dec 10 '11 #10
ADezii
8,834 Expert 8TB
I have not read the entire Thread in detail, so forgive me if I oversimplify, but couldn't the entire Scheduling Issue be resolved by simply calculating from a Base Date? To Execute a Code Segment at specific Intervals starting from #11/10/2011# (30 Days today) would require the following Logic:
Expand|Select|Wrap|Line Numbers
  1. Dim dteBaseDate As Date
  2.  
  3. dteBaseDate = #11/10/2011#
  4.  
  5. If (DateDiff("d", dteBaseDate, Date) Mod 7) = 0 Then
  6.   '1 Week Interval has happened
  7. End If
  8.  
  9. If (DateDiff("d", dteBaseDate, Date) Mod 30) = 0 Then
  10.   '30 Day Interval has happened
  11. End If
  12.  
  13. If (DateDiff("d", dteBaseDate, Date) Mod 365) = 0 Then
  14.   '1 Year Interval has happened
  15. End If
P.S. - Again, forgive me if I oversimplify, or am off on another Tangent which happens quite frequently! (LOL).
Dec 10 '11 #11
NeoPa
32,556 Expert Mod 16PB
From within the timer procedure that code could work. It's hard-coded though, and inflexible. I would suggest a data-based solution would probably be required (as the OP's database is already somewhat sophisticated already). It could work though :-)
Dec 10 '11 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Colin Steadman | last post by:
We have a number of scheduled tasks on our IIS server that run daily at some point during the early morning. These tasks run as a specific user that has the correct permissions to perform whatever...
3
by: Greg D. Moore \(Strider\) | last post by:
Ok, I thought this one would be easy. I have a stored proc: master.dbo.restore_database_foo This is on database server B. Database server A backs up database foo on a daily basis as a...
5
by: A. Lovhaug | last post by:
I have a console application built in the .NET Framework. This application basically executes an XCopy based on parameters that I pass to it. I use it for creating scripts for backing up folders,...
2
by: David Olive | last post by:
Hi guys, I'm having a bit of a problem getting a VB .NET console app to run happily as a scheduled task. The app itself generates a bunch of word documents on a file share on another server by...
6
by: John Bowman | last post by:
Hi, I have a C# app that needs to launch the "Add Scheduled Tasks" wizard found in the control panel "Scheduled Tasks" applet. I realize that this "applet" really just opens the tasks folder,...
1
by: satelite | last post by:
Hello, I am writing an exe that is intended to be run via a scheduled task. However, I also need the flexibility to have users run the scheduled task manually (right click task and select run). ...
9
by: helpful sql | last post by:
Hi all, I want to write a .Net solution that I would like to run as a scheduled task in windows. I am not going to need any user interface. What I don't understand is what kind of project I need...
1
by: Myster Edd | last post by:
I have a strange problem that I think deals with security on SQL 2005. I have a scheduled task that runs on a Windows 2000 machine. It calls a vb script which creates a connection to SQL Server. ...
0
by: Paulson | last post by:
Dear Freinds I want to make a program that acts as a reminder for the users.I need to open up the Scheduled task wizard programmatically.If you type Tasks in the run command the Tasks...
9
by: jdaelhousen | last post by:
I have a bit of a problem I'm hoping someone can shed some light on... I have a VB.Net console application written in VS 2003 that produces a .exe file that now sits on a Windows 2000 server...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.