running code daily (1 Viewer)

shutzy

Registered User.
Local time
Today, 02:56
Joined
Sep 14, 2011
Messages
775
im wondering if there is a way to run code daily. i have in mind to run a delete query every day. the query would be to delete any record where the date is <DateAdd('yyyy',-1,date())

i have other update queries and things that i would like to be automated every day and would like to not have to think about them again.

any suggestions?

thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:56
Joined
Aug 30, 2003
Messages
36,128
Personally I'd create a db that did those functions when it opened, then it closes itself. Then I'd run that db from Windows Scheduled Tasks.
 

Solo712

Registered User.
Local time
Yesterday, 21:56
Joined
Oct 19, 2012
Messages
828
Personally I'd create a db that did those functions when it opened, then it closes itself. Then I'd run that db from Windows Scheduled Tasks.

I routinely use command line switches to run chores in Excel apps with the scheduler. The thing is though, Excel allows access to the cpmmand line arguments from the open Application module. In Access I see only preset command line switches. Not even sure I can run the /x macro if I have Autoexec as part of the setup. Does the /x switch disable the autoexec macro ? Thanks.

Best,
Jiri
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:56
Joined
Aug 30, 2003
Messages
36,128
Does the /x switch disable the autoexec macro ?

Not sure, I don't use macros so haven't used the command line switch. I just create a db that just does my desired task; I don't try to make a production db also do the scheduled stuff. It's easy enough to export out the parts I need to a new db.
 

Solo712

Registered User.
Local time
Yesterday, 21:56
Joined
Oct 19, 2012
Messages
828
Not sure, I don't use macros so haven't used the command line switch. I just create a db that just does my desired task; I don't try to make a production db also do the scheduled stuff. It's easy enough to export out the parts I need to a new db.

Ok, fair enough.

Jiri
 

Solo712

Registered User.
Local time
Yesterday, 21:56
Joined
Oct 19, 2012
Messages
828
I have done some quick checking of the /x switch. It does not displace/bypass the autoexec macro which may or may not be an issue with specific applications. At worst, another routing from the x-switch will have to be supplied to replace autoexec.

As for the macro itself it can be any macro. You can use RunCode wich takes the argument of a function declared in a module:

ie. define macro MyBatchProcess as:

Runcode SwitchTest()

Then, in a module, define the function :

Code:
Public Function SwitchTest()
 
   ' place executable code here
   DoCmd.Quit
 
End Function

As a final step, define the command line for this particular run of your database:

"C:\Program Files\Microsoft Office\OfficeX\MSACCESS.EXE" c:\path\MyApp.accdb /x MyBatchProcess

The database will open, execute the function and its subroutines and close again. When designing batch processes you will need to handle errors with the view that the run is unattended. Ie, trap and log errors rather than handle them through user dialogue.

Best,
Jiri
 

Users who are viewing this thread

Top Bottom