How can I invoke MS Access at command-line level and no UI?

G

Guest

In a single batch file, I want to load text files into an MS Access database,
run some updates, and select queries to spool the data.
Can MS Access be invoked at command-line level, without showing up the UI??
 
D

Douglas J Steele

rkallakuri said:
In a single batch file, I want to load text files into an MS Access database,
run some updates, and select queries to spool the data.
Can MS Access be invoked at command-line level, without showing up the
UI??

No, it can't. However, it should be possible to load data without having to
actually open the Access GUI using VBScript. You'd have to have Access
installed on the same machine, of course, but you should be able to automate
it using something like

Dim objAccess

Set objAccess = CreateObject("Access.Application")
objAccess.DoCmd.TransferText ....
objAccess DoCmd.RunSQL ...

and so on.

I'm not sure I understand what you mean by "spool the data", though.
 
G

Guest

Doug,

Thanks a lot for the response. By spooling, I meant getting the result of
some SQL statements into text files again.
But, we have a predefined Access database with tables, queries and macros.
Can we invoke all these using a VB?

Regards,
Kallakuri.
 
A

Albert D.Kallal

By command line, I assume you mean windows batch files?

Sure, you can create a blank text document. (you need to turn on display of
file extensions to do this).

Just put the following code in a text file

dim accessApp

msgbox "Click ok to run batch job",64

set accessApp = createObject("Access.Application")

accessApp.OpenCurrentDataBase("C:\Documents and Settings\Albert\My
Documents\MyDatabase\batchstuff.mdb")

accessApp.Run "TimeUpDate"

accessApp.Quit

set accessApp = nothing

msgbox "Job complete", 64

After you type in the above windows script simply save the above. Now,
rename the above to mybatch.vbs. Note how the file icon changes. If you
double click on this file, then the windows batch file will run. If you plan
to use the script in the scheduler, you would of course remove the msgbox in
the above. You can also use

wscript.Echo "about to run"

If you at the command prompt use

cscript mybatch.vbs

Then, all output goes the test console, and the script will NOT halt.
However, if you click on the script (mybatch.vbs in this example), then you
will get a dialog box.

If you use msgbox in place of wscript.Echo, then EVEN when you use cscript
(console script), the msgbox will appear.


Further, the above mdb file of course would NOT have any startup forms, or
startup stuff. Often, I just make a new mdb, and LINK the tables to the
required applications, and that way you don't have any problems with the
startup forms etc.

The above windows script would simply launch ms-access, and then run a
public sub called TimeUpDate. At this point, you can then use the scheduler
and place the vbs script in the windows scheduler.

You can even run the above in the dos window. Just type in

start mybatch.vbs (of course, whatever the name you used..along with
full path name etc. would be required).

If you don't want to actually write a windows script as a above, then you
can just make mdb file that runs your code when you start it (don't forget
that if you do this, your code in ms-access HAS TO EXIT the application (use
application.quit).

So, in place of the above script, you can from the windows dos prompt, just
type in

start myBatcth.mdb

The above example just launches a mdb file called mybatch. Of course either
a form set via the startup options, or a autoexec macro would then run, and
then quite.

So, I think the windows script is a bit more flexibly, as your script gets
to choose what subroutines gets called.

note that you can go

start hello.doc

The above would start word, and open the above document. So, start is as if
you clicked on the document, but is run from the command prompt.
 
P

Paul Overway

Depending on what you are doing, you might not need to use Access at all.
For example, if you are just executing a series of queries or manipulating
data, you could use DAO in VBScript.
 
A

aaron.kempf

yes, you can run it through the command line.

MSACCESS.exe C:\mydbfile.mdb /X MACRONAME
 
L

Larry Linson

yes, you can run it through the command line.

MSACCESS.exe C:\mydbfile.mdb /X MACRONAME

Very good, Aaron. Now show what has to be added to get the "no user
interface" part of the requirement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top