Code to run at DB Startup

Alan R

Registered User.
Local time
Today, 06:04
Joined
Sep 11, 2006
Messages
70
Hi all,

I have a question concerning code that i would like to add that runs each time the database is started but is only actioned if the date matches. For example on or around the last day of each month i want some 'housekeeping' tasks to be completed automatically and in the background and then for a pop-up message to appear to remind users of certain other tasks they need to undertake.

The coding shouldn't be a problem but i am just wondering where would be the best place to locate the code?

The DB opens to a form and not the Switchboard when first started.

Many Thanks

Alan
 
Insert the code in the first form
 
Orna,

Thanks for that, i guessed that it would work from there but just wondering if anybody knew of a more efficient way of achieving that.

I have another question.

There is a requirement to back up the database and 'empty' some of the tables using a delete query after the same particular date every year. i have the back up and delete queries working a treat and i can get it all to work if i compare a date with 'set date' i.e. it checks to see if todays date is equal to or greater than, say, 31/8/2007. my problem now is that if i add new records to the purged db and then close and reopen the db, it purges them again. eventually i am hoping to get it to do the actions once on or around the same date each year. i have a couple of ideas and normally i would work at it until i had either figured it out or had thrown my laptop out of a window but this is time limited so any assistance will be greatly appreciated.

Regards

Alan
 
Best practice is probably to put the code in a module then call it from the open event of your form rather than actually have it in the form, although it doesn't actually make any difference in coding terms.

Sounds like you have the 'set date' hard-coded somewhere. You need to store it in a table then, when your purge code has successfully run, update the date by adding a year to it.
Might be an idea to run your purge code in a transaction so that you can be sure it all finishes successfully before you update the date. You don't want it to fall over on the first back-up and have to wait a year for your next chance!
 
Put it in a module and use an autoexec macro to run it is what I would do.
 

Users who are viewing this thread

Back
Top Bottom