Batch File

sparx

Morphed Human
Local time
Today, 06:28
Joined
Jul 22, 2002
Messages
80
I would like to create a batch file to open up an Access database at a given time and then close it at a later time. Does anyone have any ideas??

Thanks in advance,

Erik
 
Hello from Hull Erik!

To get you started, look up the "at" function. It will allow you to schedule a file to run at a certain time.

I can't test it here because I'm at work and they have disabled it (I would need Admin privileges) - security reasons I assume.

Out of curiosity, what are you trying to accomplish? Is it just so users will have it open when they get to work, and it will shut down later in case they forgot? I'm just always interested in the uses for Access that people can come up with!

Later,
-Sean
 
reasoning

The reason I need to run a batch file to do this is that I need to schedule a job at 3am everyday that will export a text file onto a server. Instead of doing it manually everyday, we will dedicate 1 pc to do the job and the pc will be up and running all nite long.
 
Have you tried using the Task shedule in Windows.
I do a similar thing but it exports an email at a certain time everyday. Even if Access isn't open you can open it, run your code and the close.
 
And if you have trouble with Nero's suggestion, then I would create a new db (linking to all the tables you need) - have the batch open the Access app using the AT function as mentioned earlier - then, have your VBA code execute in the On_Load procedure of the app. End your VBA code with "DoCmd.Quit" to close Access which will allow the batch shell to be able to close as well (provided your last line in your batch file is "Exit")

Let us know what you end up doing!

-Sean
PS If the DOS screen still won't close after, then add a carriage return after "Exit" before saving the batch.
 
at function??

Where do I find this so-called "at" function?? I've searched the help in both vba and access and have found nothing. I tried searching for threads using the same function and was also unsuccessfull. Please let me know where to find info about this "AT" function, because I've never heard of it.

Thanks,

Erik
 
ignore last post

Nevermind, I'm sorry about my ignorance, I didn't realize the "at" function was a dos command..
 
At work we run lots of db's automaticaly. Use .bat file to launch Access and suggest that you use the macro launch switch /X followed by macro name. In the macro get it to run the VBA code using the RunCode command. NOTE: for RunCode, it calls a function NOT a sub. Reason for using /X rather than on_load is that if you want to open the database for maintenance you don't want the code to run which it would with on_open

Example for the batch file, where db is on D:\

"C:\program files\microsoft office\office\msaccess.exe" d:\myfiles\mydb\test.mdb /X Launch_Auto

This is calling a MACRO called Launch_Auto

For the macro I would have the code:

RunCode 'Place the function name of the VBA script
Quit


HTH
 
Good one Harry! The reason why I suggested a new database with linked tables was because I couldn't think of another way to make sure that the code would run when the batch opened it.

Cheers!

-Sean
 

Users who are viewing this thread

Back
Top Bottom