Solved

run vba from command prompt

Posted on 2004-08-22
12
3,765 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 49

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

709 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now