Solved

Batch file for MS ACCESS

Posted on 2007-04-04
13
450 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

761 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