views:

58

answers:

2

I'd like to have a macro, called Macro1, for example, run every day at 9 AM. It works great on its own from the VB code editor in Access 2007 but I would like it to be able to execute automatically without access being open.

Please note that I don't want there to have to be any human intervention, it needs to be able to run automatically without someone opening Access to trigger autoexec or onload or something similar.

Is this at all possible?

+3  A: 

You can use Windows Task Scheduler and VBScript to run code or start Access.

Remou
So I would essentially schedule a script to run every day at a certain time and then have that script open access and execute a macro? Is this doable?
alexcoco
...assuming, of course, that what the macro ultimately does is something that can be done through DAO or via Access automation.
David-W-Fenton
+4  A: 

You can use a MS Access command line switch to run a macro. If you search for "commandline" in Access help, the topic "Startup command-line options" gives you all the commandline switches. The switch for running a macro is x macro.

So, if you write your macro to run whatever you want and have it exit Access when it finishes, you can then create a commandline that will do the trick and put it in a batch file that the Windows Task Scheduler can execute.

However, as I said in a comment above, if you are just running some queries, I'd say it makes more sense to bypass Access entirely and use DAO directly in a scheduled vbScript to execute the queries.

David-W-Fenton
This sounds good. It's not just some queries although that is part of it. I need to query a linked table from another database and update content in the current database.
alexcoco
Oh, and thanks for the thorough answer, I appreciate it!
alexcoco
I'm not sure what the differences is between running some queries and "querying a linked table...and updating content in the current database" -- isn't that done by running a query? If it's not, maybe it should be?
David-W-Fenton
Yeah, it is done by querying it. But then I need to use the results to update part of another local table.
alexcoco
I'm still not getting why "using the results to update" something else prohibits what I'm suggesting.
David-W-Fenton
@alexcoco -- I think what David's getting at is that your update can (and probably should) be done using an update query, which would mean that you're still "running some queries", nothing more.
RolandTumble
I've got one row that contains three fields that contain information from one row each from a linked table. That's why I can't just run an update query because each row in my table has to be updated three times, once in every field. Unless I run three update queries. I suppose it is unnecessarily complicated but the linked tables are managed by another software and it seems to like making things complicated.
alexcoco
I don't get why you consider running three updates a problem.
David-W-Fenton
I suppose I just didn't think of it earlier. I'm studying in Computer Sciences and I'm not an Access pro just yet. I was asked to set up a few reports and it turned into this big mess.
alexcoco
@alexcoco: Welcome to the real world!
David-W-Fenton
@David-W-Fenton: Hah, yes, indeed. Thanks for the help!
alexcoco