Solved

run vba from command prompt

Posted on 2004-08-22
12
3,801 Views
Last Modified: 2012-09-07
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
0
Comment
Question by:itc307
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +4
12 Comments
 
LVL 26

Expert Comment

by:dannywareham
ID: 11863907
What is your code...?
Can you post it please?
0
 
LVL 12

Expert Comment

by:0tacon
ID: 11863920
What are you trying to accomplish by running this script from the command prompt?

You could always create an autoexec macro :)
0
 

Author Comment

by:itc307
ID: 11863935
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:dannywareham
ID: 11863947
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
 
LVL 5

Expert Comment

by:Ideefiks
ID: 11863981
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
 

Author Comment

by:itc307
ID: 11864027
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
 
LVL 12

Expert Comment

by:0tacon
ID: 11864035
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
 
LVL 12

Accepted Solution

by:
0tacon earned 500 total points
ID: 11864063
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
 
LVL 12

Expert Comment

by:0tacon
ID: 11864077
Also for reference about autoexec macro control:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;160951
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 11864093
try run your vbscript, then save it as .vbs ?
0
 
LVL 9

Expert Comment

by:solution46
ID: 11865043
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
 
LVL 5

Expert Comment

by:NashvilleGuitarPicker
ID: 11874473
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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question