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

x
?
Solved

Batch file for MS ACCESS

Posted on 2007-04-04
13
Medium Priority
?
454 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
[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
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

670 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