Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

run vba from command prompt

Posted on 2004-08-22
12
Medium Priority
?
3,853 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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 1500 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 53

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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