Solved

run vba from command prompt

Posted on 2004-08-22
12
3,786 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 50

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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 …

856 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