run vba from command prompt

hi,
i have written a vba script in microsoft access 2000. I want to run this from the command prompt. I need to do so to make a *.bat file. Is it possible to do so? If so, how?

thanks
sanjana
itc307Asked:
Who is Participating?
 
0taconConnect With a Mentor Commented:
You will need to create a MACRO in the database which contains/points to the code you wish to run. You can then call this from the command prompt using the code specified in the following link..for fear of repetition I wont replicate the answer here- good luck :)

http://www.experts-exchange.com/Databases/MS_Access/Q_20686272.html
0
 
dannywarehamCommented:
What is your code...?
Can you post it please?
0
 
0taconCommented:
What are you trying to accomplish by running this script from the command prompt?

You could always create an autoexec macro :)
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
itc307Author Commented:
hey,

i haven't created any macro. I haven't created the .bat file as yet. The thing is I have written  a vba script (which is working properly). I need to run this vba script everyday. For this I need to create the .bat file and add to the task schedular. To do so I need to know how to run the vba script from the command prompt.

sanjana
0
 
dannywarehamCommented:
Can you post your VBA script please?

It sounds like you want to click a button on a form that sends the details to the command prompt...?
0
 
IdeefiksCommented:
Why not put the macro in the Open event of a start up form and have the database close when it finishes?
The bat file would then simply open the file that contains the macro.

greetz.
0
 
itc307Author Commented:
Hey,
I cannot use macros!!! I am not using any buttons either though I can use that. Regardless, how can run this script from the command prompt.

thanks
sanjana
0
 
0taconCommented:
It sounds like you need to run a VB script which is PART of a database and then schedule that using task manager?

All you have to do is the following- create an autoexec macro OR call the VB code to the open event of a startup form as IDEEFIKS mentions. Follow this with a flag which recognises if the database has been opened by task manager and can close it automatically.

The database will HAVE TO BE opened to run any component VB code, you cant simply call the code alone im afraid
0
 
0taconCommented:
Also for reference about autoexec macro control:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;160951
0
 
Ryan ChongCommented:
try run your vbscript, then save it as .vbs ?
0
 
solution46Commented:
sanjana,

by far the best bet (as has been mentioned several times above) is to have an autoexec macro (plenty of on-line help about this with Access) and close the database down when the tasks are finished.

However, if you particularly don't like this approach for some reason, there are two other possiblities.
1. Untidy but works...
Leave Access open on a mahcine where it wont get disturbed. Set the on_timer event of a form to run the code and set the timer to a suitable number (again, there is plenty of online help about this within Access).

2. Tidy & efficient but requires programming.
Use VB or any other language you're comfortable with to write a small .exe that connects to your .mdb file via ADO and carries out whatever commands you need it to. Run this from Windows Scheduler.


I would probably opt for option 2 above as a preference, but if your coding skills are limited then definately go for the autoexec macro approach.

Regards,

s46.
0
 
NashvilleGuitarPickerCommented:
If you don't need to load Access every time then you should be able to Does your macro require data from the database?  If not, you may want to use Windows Script instead of Access.  You can also connect to Access databases from Windows Script, if needed.

See http://www.micosoft.com/scripting/ formore info on Windows Script Host.

If it is data intensive, though, it may make more sense to use the AutoExec macro.  You can have the macro call your VBA code.  We used to do this all the time.  It was our only macro, and it called the main menu from the VB code.

- Will
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.