Solved

Batch file for MS ACCESS

Posted on 2007-04-04
13
451 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

752 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