Solved

Batch file for MS ACCESS

Posted on 2007-04-04
13
448 Views
Last Modified: 2013-11-28
I need to create a batch file that I can run through task scheduler to open a Microsoft Access datbase and call a Macro in the database at a specified time every day. I can setup the task scheduler, but I need an idea for the basic structure of the batch file to do this.
0
Comment
Question by:StephenJD
  • 6
  • 4
  • 3
13 Comments
 
LVL 9

Expert Comment

by:TheSloath
ID: 18854898
You can use the /x command line switch to run a macro, e.g.:

msaccess.exe MtDB.mdb /x MyMacro
0
 
LVL 4

Author Comment

by:StephenJD
ID: 18855039
Does this look like it will do the trick? :

@echo off
start /w msaccess.exe MtDB.mdb /x MyMacro

0
 
LVL 9

Expert Comment

by:TheSloath
ID: 18855279
Looks perfect
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 4

Author Comment

by:StephenJD
ID: 18855380
Ok here is what I have:

@echo off
Start /w "C:\Program Files\Microsoft Office\OFFICE11\msaccess.exe" "C:\Access\AUTOREPORTS\REPORTS.mdb" /x "MAC_TEST_AUTOMATION"

This is opening the Database, but it is not running the Macro.
Where am I going wrong here? I've tried it without the quotes on the macro name, and I have also tried adding an additional line to call the macro seperately ( Call /x "MAC_TEST_AUTOMATION") of course without the parenthesis. I have also tried the call line with no quotes, but the Macro will not run. The DB security is set to low so that shouldn't be the problem...
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18855386
you need path stuff...

"C:\Program Files\Microsoft Office\ART\Office\MSACCESS.exe /User username /Pwd password /Wrkgrp C:\System.mdw  c:\mydatabase.mdb /X MacroName

you may not need the username, password or workfile

J
0
 
LVL 9

Expert Comment

by:TheSloath
ID: 18855394
I ran it fine without the path to msaccess.exe, you prob need the path to the MDB, unless the batch file and MDB are in the same folder.

You don't need the quote marks round the macro name:

@echo off
Start /w "C:\Program Files\Microsoft Office\OFFICE11\msaccess.exe" "C:\Access\AUTOREPORTS\REPORTS.mdb" /x MAC_TEST_AUTOMATION
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18855399
create a msgbox entry as the first entry in your macro, to test if the macro is even firing...maybe it's the report itself...a parameter that's not getting satisfied?
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18855406
do it without the start /w and make sure there's a space in the middle between the Program an the File
0
 
LVL 34

Accepted Solution

by:
jefftwilley earned 500 total points
ID: 18855409
@echo off
"C:\Program Files\Microsoft Office\OFFICE11\msaccess.exe" "C:\Access\AUTOREPORTS\REPORTS.mdb" /x MAC_TEST_AUTOMATION
0
 
LVL 4

Author Comment

by:StephenJD
ID: 18855410
That's the problem. The macro isn't even firing. All I have the test macro doing is emailing me a table in Excel Format, then quitting the application. The macro runs good when I run it maunually.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18855418
that's got it?
0
 
LVL 4

Author Comment

by:StephenJD
ID: 18855424
That was the problem. The start /w was killing me apparently.

Thanks to both of you.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18855427
happy to help.
J
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

813 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

17 Experts available now in Live!

Get 1:1 Help Now