Solved

Batch or Command File That Runs Custom Sub in Access 2007 Database

Posted on 2013-11-01
5
474 Views
Last Modified: 2013-11-04
I thought I would find my answer in old posts on this topic but couldn't quit find what I was looking for so appoligize in advance if I missed something.

I am looking for a batch file that will execute an Access database custom procedure stored in a standard module. All the code does is run a few Make Table Queries. I would like to provide the file to a few users so that it minimizes their direct interaction with the database itself.

Any assistance with this would be much appreciated. Thank you.
0
Comment
Question by:spaced45
  • 2
  • 2
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39617631
Add a Macro to your database, using the RunCommand action to run your function (I believe it needs to be a function, not a Sub).

You can then create a shortcut to open the database, running your macro with this as the target:

"c:\program files\microsoft office\office12\msaccess.exe" "c:\MyFolder\MyDatabase.accdb" /x MyMacro

Open in new window



Change "office12" to reflect the path to the version of Access you have installed, the database path to your own database, and the macro name to your own macro.
0
 
LVL 57
ID: 39617708
The other way to do this is with the /CMD switch on the command line, which let's you pass multiple parameters in and react to them.

 WIthin Access, you use the Command() statement to get what was passed in.

 Based on that, you can then call procedures, run reports, put up forms, or whatever.

Jim.
0
 
LVL 1

Author Comment

by:spaced45
ID: 39622640
Is there a way to not have the database open when you click on the shortcut.
0
 
LVL 57
ID: 39622742
No.  Access will open and execute the macro.  There's no avoiding that with Access iteself.  You can hide the main window as soon as it opens, but you will see a flash.  Error handling needs to be very robust however as any type of unhandled error will result in your app sitting there with you being able to do anything about it.

Outside of Access itself, you could write a "launcher" program that would remain hidden, open Access via OLE automation and also keep it hidden.

Jim.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39623085
In addition to what Jim said (and similar), another possible way to achieve this is to use other development platforms - vb.Net, C#, VBScript are some possibilities.

You'd open a connection to your Access tables with a connection string rather than using automation or directly opening Access with a shortcut.

The downside is that with this you only have access to the tables - you'd have to write and execute the queries in VB.Net (or whatever language).  It is also code intensive - similar in that respect to Access automation, and would be a bit of a learning curve if you are not familiar with that type of coding.

The upside is that you'd have a neatly packaged executable that you could distribute to your users, or a web-based interface. And a plus from a developer's standpoint is that the code for connecting to access, executing the queries, and the queries themselves would all be in one place/one environment.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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…
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.

747 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

18 Experts available now in Live!

Get 1:1 Help Now