Solved

Batch file for MS ACCESS

Posted on 2007-04-04
13
446 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

758 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

20 Experts available now in Live!

Get 1:1 Help Now